// --------------------------------------------------------------------------------------------------------------------------------------------------------
function reportSubmissionToServer(map, e, form, claimStatus) {


	e.preventDefault(); // avoid to execute the actual submit of the form.
	//var form = $(this);
	var empId_date = form.attr("data-common-id");
	var rowIndex = form.attr("data-index");
	//var presentIndex=empId_date+"_"+rowIndex;

	//gathering all value's from UI by its id's("empid,date,reason, deputation, daAmount, Total")
	var engg_empId = $("#empId_" + empId_date).html();
	var presentDate = $("#siteVisitDate_" + empId_date).html();
	var presentSerialNumber = Number($("#sNo_" + empId_date + "_" + rowIndex).html());
	var ReasonToDeductOrReject = $("#reasonPara_" + empId_date).html();
	var report_Submitted_date = $("#reasonPara_paidDate_" + empId_date).val() || getDate(new Date()); // if paid is null or undefind pass currnt-date
	var DepuationAllowance = $("#editableDeputation_" + empId_date).val();
	var DaAmount = $("#editableDaAmount_" + empId_date).val();
	var Total = $("#editableTotalFinalAmount_" + empId_date).html();
	var totalHotelBillAmount = $("#editableTotalHotelBillAmount_" + empId_date).html();
	var totalOtherBillAmount = $("#editableTotalOtherBillAmount_" + empId_date).html();


	if (LOGGED_IN_DEPARTMENT == TL_DEPARTMENT) { //constant variable in constant.js
	    let engineerTotalFinalAmout=Number($("#engineerTotal_"+empId_date).html());
		var totalLoggedInUserDeductedAmount = Number(Total) - engineerTotalFinalAmout;// TlAmount-EngTot= Tl deducted amount
		var allTotalDeductedAmount = totalLoggedInUserDeductedAmount + Number(map.get("financeDeductedAmount" + empId_date));
	} else if (LOGGED_IN_DEPARTMENT == FINANCE_DEPARTMENT) { //constant variable in constant.js
	    let TLTotalFinalAmout=Number($("#TLTotalTd_"+empId_date).html());
		var totalLoggedInUserDeductedAmount = Number(Total) - TLTotalFinalAmout;// FinanceTotAmount-TLTot=  finnce deducted amount
		var allTotalDeductedAmount = totalLoggedInUserDeductedAmount + Number(map.get("tlDeductedAmount" + empId_date));
	}

/*	var loggedInUserDeductAmount = Number(Total) - Number(map.get("beforeDeductingTotalAmount" + empId_date));
	if (LOGGED_IN_DEPARTMENT == TL_DEPARTMENT) { //constant variable in constant.js
		var totalLoggedInUserDeductedAmount = Number(map.get("tlDeductedAmount" + empId_date)) + loggedInUserDeductAmount;
		var allTotalDeductedAmount = totalLoggedInUserDeductedAmount + Number(map.get("financeDeductedAmount" + empId_date));
	} else if (LOGGED_IN_DEPARTMENT == FINANCE_DEPARTMENT) { //constant variable in constant.js
		var totalLoggedInUserDeductedAmount = Number(map.get("financeDeductedAmount" + empId_date)) + loggedInUserDeductAmount;
		var allTotalDeductedAmount = totalLoggedInUserDeductedAmount + Number(map.get("tlDeductedAmount" + empId_date));
	}*/
	/*----------------------------------------------------------------------------------------------------*/
	// checking change done or not, by comparing before and after changes values
	/*----------------------------------------------------------------------------------------------------*/
	/*  if (map.get("deputation" + presentIndex) == DepuationAllowance) {
	      DAamountchangeDone = "No";
	  } else {
	      DAamountchangeDone = "Yes";
	  }*/
	$("#reportSubmissionBtn_" + empId_date + " i").removeClass("d-none");

//	checkWheatherLogoutOrNot(); // before request-call to server checking user is still logged in or not

	/*----------------------------------------------------------------------------------------------------*/


			let object = {};
			postContent_CommonArrays(object);
			let postContentValues = JSON.stringify(object);
			makeAjaxCall(postContentValues);
			//console.log("projectValue_Array.length="+projectValue_Array.length+"idValue_Array.length="+idValue_Array.length+"stageOfAuditValue_Array="+stageOfAuditValue_Array.length+"FTAValue_array.length"+"distanceValue_Array"+distanceValue_Array.length);
				// if (LOGGED_IN_DEPARTMENT == TL_DEPARTMENT) {
				// 	if(projectValue_Array.length==idValue_Array.length  && stageOfAuditValue_Array.length==idValue_Array.length && 
				// 	   FTAValue_array.length==idValue_Array.length && idValue_Array.length!=0){
				// 	   makeAjaxCall();
				// 	   }else{
				// 	       $("#reportSubmissionBtn_" + empId_date).html("Retry <i class='fa d-none fa-spinner fa-spin mr-2'></i>");
				// 	        //$("#reportSubmissionBtn_" + empId_date + " i").addClass("d-none");
				// 		   alert("In Report submission the Any of these (project,fat, satgeOfAudit)Array Values not Equal To server_id Array");
				// 	   }
				// }else if (LOGGED_IN_DEPARTMENT == FINANCE_DEPARTMENT){
				// 	if(distanceValue_Array.length==idValue_Array.length  && projectValue_Array.length==idValue_Array.length  && stageOfAuditValue_Array.length==idValue_Array.length && 
				// 	   FTAValue_array.length==idValue_Array.length && idValue_Array.length!=0){
				// 	   makeAjaxCall();
				// 	   }else{
				// 	      $("#reportSubmissionBtn_" + empId_date).html("Retry <i class='fa d-none fa-spinner fa-spin mr-2'></i>");
				// 	       //$("#reportSubmissionBtn_" + empId_date + " i").addClass("d-none");
				// 		    alert("In Report submission the Any of these (distance,project,fat, satgeOfAudit)Array Values not Equal To server_id Array");
				// 	   }
				// }
	
			 // function call




	/*----------------------------------------------------------------------------------------------------*/
	/*submiting all (claim-status, da-amount, total, deductedamount, allTotalDeductedAmount ) to update*/
	/*--------------------------------------------------------------------------------------------- -------*/
	function makeAjaxCall(postContentValues) {
	//	console.log(postContentValues);
		$.ajax({
			type: "POST",
			url: "php/ReportSubmit.php",
			timeout:STANDARD_TIME_OUT,
			//dataType: "JSON",
			data: {
				paramValues: postContentValues
			}, 
			success: function (responseData) {
				//console.log(responseData);
				if (responseData == "UPDATED") {
					var noOfDuplicateRows = $(".data-content_" + empId_date).length;

					// on  TLapproved/rejected/FinanceApproved  deleting claim from these tab
					$(".data-content_" + empId_date).remove();
					$(".image-content_" + empId_date).remove();

					$(".td.serialNumber").each(function () {
						let sno = Number($(this).html());
						//in between any claim deleted change sno from greater than presentSerialNumber.
						if (presentSerialNumber < sno) {

							let updateSNO = sno - noOfDuplicateRows;
							$(this).html(updateSNO); // changing every serial Number.
						}
					});
				} else {
					$("#reportSubmissionBtn_" + empId_date).html("Retry <i class='fa d-none fa-spinner fa-spin mr-2'></i>");
				}

				var lenghtOfTableTr = $("#inserted_tableBody_data tr").length; // if last claim deleted print no claims left
				if (lenghtOfTableTr <= 0) {
					adjustUIDataNotFound();

				}

			},
			statusCode: {
    			    404: function(){
    			        alert("requesting file(ReportSubmit) does not exists! in server");
    			    }
    			},
			error: function (jqXHR, textStatus, errorThrown) {
			    /*if(textStatus=="timeout"){
			       $("#reportSubmissionBtn_" + empId_date).html("Retry <i class='fa d-none fa-spinner fa-spin mr-2'></i>");
			    }*/
			     $("#reportSubmissionBtn_" + empId_date).html("Retry <i class='fa d-none fa-spinner fa-spin mr-2'></i>");
				console.log("ajax error in report submition");
			}
		});
	}
	/*---------------------------------------------------------------------------------------------*/


	function postContent_CommonArrays(ref_object) {

		$.each(form.serializeArray(), function (i, obj) {
			ref_object[obj.name] = obj.value;
			//console.log(form.serialize());
		});

		ref_object['empId'] = engg_empId;
		ref_object['presentDate'] = presentDate;
		ref_object['Reason'] = ReasonToDeductOrReject || "";// if value null or undefinrf pass ""empty
		ref_object['report_date']=report_Submitted_date;
		ref_object['DepuationAllowance'] = DepuationAllowance || "";
		ref_object['DaAmount'] = DaAmount || "";
		ref_object['hotelBill'] = totalHotelBillAmount || "";
		ref_object['otherBill'] = totalOtherBillAmount || "";
		ref_object['TotalAmount'] = Total || "";
		ref_object['loggedInUserDeductAmount'] = totalLoggedInUserDeductedAmount || "";
		ref_object['allTotalDeductedAmount'] = allTotalDeductedAmount || "";

	}


}




// ;;