Web Developer Work - I
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
19 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. import FeatureLayer from '@arcgis/core/layers/FeatureLayer'
  2. import esriRequest from '@arcgis/core/request';
  3. import { execute } from '@arcgis/core/rest/geoprocessor';
  4. import { submitJob } from '@arcgis/core/rest/geoprocessor';
  5. import { notifyResultData } from 'dist/widgets/arcgis/analysis/src/utils/events';
  6. import { FaHippo } from 'react-icons/fa6';
  7. interface GPServiceResponseItem {
  8. MatchedData?: string;
  9. misDataNull?: string;
  10. 'Property Count'?: number;
  11. ConsolidatedValues?: any[];
  12. NodueData?: string;
  13. DueData?: string;
  14. }
  15. const Property_w_54 = new FeatureLayer({
  16. url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/Buildings_Revenue_MIS/MapServer/1"
  17. })
  18. const building_queryLayer = new FeatureLayer({
  19. url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/SurveyTables/FeatureServer/0"
  20. })
  21. const Property_queryLayer = new FeatureLayer({
  22. url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/SurveyTables/FeatureServer/4"
  23. })
  24. const Floor_queryLayer = new FeatureLayer({
  25. url: "https://gisgcc.chennaicorporation.gov.in/server/rest/services/Revenue/SurveyTables/FeatureServer/2"
  26. })
  27. export const fetchGISIDFetch = async (GISIds: any) => {
  28. try {
  29. let gisID_input
  30. if (typeof GISIds == 'string') {
  31. gisID_input = GISIds
  32. }
  33. else if (GISIds && GISIds.length == 1) {
  34. gisID_input = GISIds[0]
  35. }
  36. else {
  37. return
  38. }
  39. let GISIdInput = gisID_input.replace(/^"|"$/g, "")
  40. // const GISIdInput = JSON.stringify(GISIds);
  41. const newAPIEndPoint = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=common_api&jsonResp=Yes&subService=getPropByGisId&gisId="
  42. // const reportInput = JSON.stringify({ inputs: { GIS_ID: GISIds } });
  43. // const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  44. // const channelID = 3;
  45. // const serviceId = 'getPropGisInfo';
  46. // const formatType = 'json';
  47. // const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(reportInput)}`;
  48. const requestUrl = newAPIEndPoint + `${encodeURIComponent(GISIdInput)}`;
  49. try {
  50. // Fetch the data
  51. const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  52. // Ensure we have the data and GisInfos is available
  53. if (apiResponse.data && apiResponse.data.ListResult && Object.keys(apiResponse.data.ListResult).length > 0) {
  54. // Filter the response to include only matching GISIds
  55. const matchingGisInfos = apiResponse.data.ListResult.filter((items: any) =>
  56. GISIds.includes(items.GISID)
  57. );
  58. return matchingGisInfos; // Return only the matching GISId objects
  59. }
  60. return []; // Return an empty array if no matching results
  61. } catch (err) {
  62. console.error('Error fetching data:', err);
  63. return [];
  64. }
  65. } catch (err) {
  66. console.error('Error querying features:', err);
  67. }
  68. return [];
  69. };
  70. export const fetchBillNoData_New = async (GISIds: string) => {
  71. try {
  72. if (GISIds) {
  73. let GISIdInput = GISIds.replace(/^"|"$/g, "")
  74. // const GISIdInput = JSON.stringify(GISIds);
  75. const newAPIEndPoint = "https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=common_api&jsonResp=Yes&subService=getPropByGisId&gisId="
  76. // const reportInput = JSON.stringify({ inputs: { GIS_ID: GISIds } });
  77. // const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  78. // const channelID = 3;
  79. // const serviceId = 'getPropGisInfo';
  80. // const formatType = 'json';
  81. // const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(reportInput)}`;
  82. const requestUrl = newAPIEndPoint + `${encodeURIComponent(GISIdInput)}`;
  83. try {
  84. const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  85. return apiResponse.data.ListResult
  86. } catch (err) {
  87. console.log('Error fetching data:', err);
  88. return [];
  89. }
  90. }
  91. } catch (err) {
  92. console.log('Error querying features:', err);
  93. }
  94. };
  95. export const fetchBillNoData = async (billNo: string) => {
  96. try {
  97. if (billNo) {
  98. const reportInput = JSON.stringify({ inputs: { P_ID: [billNo] } });
  99. const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  100. const channelID = 3;
  101. const serviceId = 'getPropGisInfo';
  102. const formatType = 'json';
  103. const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(reportInput)}`;
  104. try {
  105. const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  106. return apiResponse.data.GisInfos
  107. } catch (err) {
  108. console.log('Error fetching data:', err);
  109. return [];
  110. }
  111. }
  112. } catch (err) {
  113. console.log('Error querying features:', err);
  114. }
  115. };
  116. export const fetchBuildingUsageData = async (buildingUsage: string, reportInput: object) => {
  117. // Simulate an API call or actual query to fetch Building Type data
  118. let query = Property_w_54.createQuery()
  119. query.where = "property_usage_mis='" + buildingUsage + "'"
  120. query.returnDistinctValues = true
  121. try {
  122. const result = await Property_w_54.queryFeatures(query)
  123. if (result.features.length === 0) {
  124. return []
  125. }
  126. else {
  127. return result;
  128. }
  129. } catch (err) {
  130. console.log('Error fetching data:', err);
  131. return [];
  132. }
  133. };
  134. // export const fetchBuildingUsageData = async (buildingUsage: string, reportInput: object) => {
  135. // // Simulate an API call or actual query to fetch Building Type data
  136. // let input = JSON.stringify(reportInput);
  137. // const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  138. // const channelID = 3;
  139. // const serviceId = 'getPropGisInfo';
  140. // const formatType = 'json';
  141. // const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(input)}`;
  142. // try {
  143. // const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  144. // if (apiResponse.data.Message === 'No Data') return [];
  145. // const gisInfos = apiResponse.data?.GisInfos || [];
  146. // const filteredData = gisInfos.filter(item => item.SystemPropertyUsage === buildingUsage);
  147. // return filteredData;
  148. // } catch (err) {
  149. // console.log('Error fetching data:', err);
  150. // return [];
  151. // }
  152. // };
  153. export const fetchBuildingData = async (BuildingQryInput: string, reportInput: object, searchFilter: string) => {
  154. let input = JSON.stringify(reportInput);
  155. const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  156. const channelID = 3;
  157. const serviceId = 'getPropGisInfo';
  158. const formatType = 'json';
  159. const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(input)}`;
  160. try {
  161. const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  162. if (apiResponse.data.Message === 'No Data') return [];
  163. const gisInfos = apiResponse.data?.GisInfos || [];
  164. const filteredData = gisInfos.filter(item => item[searchFilter] === BuildingQryInput)//gisInfos.filter(item => item.SystemBuildingType === BuildingQryInput);
  165. return filteredData;
  166. } catch (err) {
  167. console.log('Error fetching data:', err);
  168. return [];
  169. }
  170. };
  171. export const fetchBuildingFloorData = async (min: any, max: any, reportInput: object) => {
  172. let input = JSON.stringify(reportInput);
  173. const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  174. const channelID = 3;
  175. const serviceId = 'getPropGisInfo';
  176. const formatType = 'json';
  177. const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${encodeURIComponent(input)}`;
  178. try {
  179. const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  180. if (apiResponse.data.Message === 'No Data') return [];
  181. const gisInfos = apiResponse.data?.GisInfos || [];
  182. const filteredData = gisInfos.filter(item => {
  183. const systemFloorCount = item.SystemFloorCount && !isNaN(Number(item.SystemFloorCount))
  184. ? Number(item.SystemFloorCount)
  185. : null;
  186. return systemFloorCount !== null && systemFloorCount >= min && systemFloorCount <= max;
  187. });
  188. return filteredData;
  189. } catch (err) {
  190. console.log('Error fetching data:', err);
  191. return [];
  192. } return [];
  193. };
  194. // Function to execute a GP service
  195. const fetchRevenueDataFromGPService = async (gpServiceUrl: string, params: any) => {
  196. try {
  197. // var gpUrl = "https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCDepts/newbillstatus/GPServer/New Bill Status Report";
  198. // submitJob(gpUrl)
  199. // .then(function (jobInfo) {
  200. // jobInfo.waitForJobCompletion().then(() => {
  201. // jobInfo.fetchResultData("Location")
  202. // .then(function (result) {
  203. // console.log(result)
  204. // })
  205. // })
  206. // })
  207. // execute(gpServiceUrl, params).then(fetchGPResult);
  208. try {
  209. const jobInfo = await submitJob(gpServiceUrl, params);
  210. console.log("Job submitted successfully:", jobInfo);
  211. const statusCallback = ({ jobStatus, progress }) => {
  212. if (jobStatus === "job-executing") {
  213. console.log(`Status: ${progress}`);
  214. }
  215. };
  216. // Wait for the job to complete
  217. await jobInfo.waitForJobCompletion({ statusCallback });
  218. if (jobInfo.jobStatus === "job-succeeded") {
  219. const availableResults = await jobInfo.fetchAllResults();
  220. console.log("Available GP Service results:", availableResults);
  221. if (availableResults.Output) {
  222. let Output = "Output"
  223. const result = await jobInfo.fetchResultData(Output);
  224. console.log("GP Service result:", result);
  225. } else {
  226. console.error("Output not found in GP service results.");
  227. }
  228. } else {
  229. console.error("Job failed with status:", jobInfo.jobStatus);
  230. }
  231. } catch (error) {
  232. console.error("Error submitting or processing GP job:", error);
  233. }
  234. async function getGPOutput(outputUrl) {
  235. const response = await fetch(outputUrl);
  236. const data = await response.json();
  237. return data;
  238. }
  239. } catch (error) {
  240. console.log('Error executing GP service:', error);
  241. throw error; // Rethrow error for further handling
  242. return []
  243. }
  244. }
  245. function fetchGPResult(result) {
  246. console.log(result)
  247. }
  248. const fetchDueDetails = (filteredProperties, MisInput, matchKey) => {
  249. // After getting the matched GIS data from the query, you can now process the filteredProperties further
  250. let dueData: any[] = [];
  251. let nodueData: any[] = [];
  252. let consolidatedDict: { [key: string]: number } = {};
  253. let nullData: any[] = []
  254. // Loop through matched API properties and apply Due/Nodue logic
  255. filteredProperties.forEach(item => {
  256. const misValue = parseFloat(item[MisInput]); // Get the MisInput value
  257. const gisId = item.GISId;
  258. if (misValue > 0) {
  259. // If there's a due, add to DueData
  260. dueData.push(item);
  261. // Consolidate by summing up misValue for each gcc_gis_id
  262. if (consolidatedDict[gisId]) {
  263. consolidatedDict[gisId] += misValue;
  264. } else {
  265. consolidatedDict[gisId] = misValue;
  266. }
  267. } else {
  268. nodueData.push(item); // No dues, add to NodueData
  269. }
  270. if (item[matchKey] === null || item[matchKey] === '') {
  271. nullData.push(item);
  272. }
  273. });
  274. // Prepare the final result
  275. const consolidatedData = Object.keys(consolidatedDict).map(gisId => ({
  276. gcc_gis_id: gisId,
  277. totalMisInput: consolidatedDict[gisId]
  278. }));
  279. // Output the final result to log or further process
  280. const resultDict = {
  281. NullData: JSON.stringify(nullData),
  282. MatchedData: JSON.stringify(filteredProperties),
  283. NodueData: JSON.stringify(nodueData),
  284. DueData: JSON.stringify(dueData),
  285. ConsolidatedValues: JSON.stringify(consolidatedData)
  286. };
  287. // console.log('FINAL RESULT:', resultDict);
  288. return resultDict
  289. }
  290. export const fetchRevenueData = async (taxType: any, MisKey: any, MisInput: any, revenueinputs: any, reportInput: any) => {
  291. const queryParams = `Zoneid=${revenueinputs.Zoneid}&WardId=${revenueinputs.WardId}&AreaId=${revenueinputs.AreaId}&LocationId=${revenueinputs.LocationId}&StreetId=${revenueinputs.StreetId}`;
  292. let report_input = JSON.stringify(reportInput);
  293. const apiEndpoint = 'https://erp.chennaicorporation.gov.in/ptis/external/collectionservice';
  294. const channelID = 3;
  295. const serviceId = 'getPropGisInfo';
  296. const formatType = 'json';
  297. const requestUrl = `${apiEndpoint}?channelID=${channelID}&serviceId=${serviceId}&formatType=${formatType}&reportInput=${report_input}`;
  298. let gpServiceUrl
  299. if (taxType == 'Property') {
  300. gpServiceUrl = 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCPropertyTax/proprevenue/GPServer/proprevenue'
  301. try {
  302. // try {
  303. // const gpResult = await fetchRevenueDataFromGPService(gpServiceUrl, revenueinputs);
  304. // return (gpResult);
  305. // } catch (err) {
  306. // console.log('Error fetching data:', err);
  307. // return [];
  308. // }
  309. // return filteredData;
  310. const apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  311. if (apiResponse.data.Message === 'No Data') return [];
  312. const revenueData = apiResponse.data?.GisInfos
  313. // const filteredProperties = apiResponse.data?.GisInfos.filter(item => {
  314. // const dueValue = item[MisInput]; // Access the queried field dynamically
  315. // const hasDues = dueValue && parseFloat(dueValue) > 0;
  316. // return hasDues;
  317. // });
  318. let resultData = fetchDueDetails(revenueData, MisInput, 'PropertyNo')
  319. return resultData
  320. } catch (error) {
  321. console.log("Error fetching Revenue API response:", error);
  322. if (error.name === 'SyntaxError') {
  323. console.log("Malformed JSON response. Verify the GP service output.");
  324. }
  325. return null;
  326. }
  327. }
  328. else if (taxType == 'Trade') {
  329. // gpServiceUrl = 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCPropertyTax/EstRevenue/GPServer/EstRevenue'
  330. const requestUrl = `https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getGisRevenueData&` + queryParams;
  331. let apiResponse
  332. try {
  333. // setInterval(async () => {
  334. apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  335. // }, 3000);
  336. if (apiResponse.data.Message === 'Connection Failure') return [];
  337. const revenueData = apiResponse.data[0].Revenue;
  338. const revenueTypeData = revenueData.find(item => Object.keys(item)[0] === taxType);
  339. let taxType_Filtered = revenueTypeData.Trade.filter(item => item.ISRENEWED === MisInput);
  340. if (taxType_Filtered.length > 0)
  341. return taxType_Filtered
  342. else return []
  343. // }, 3000);
  344. } catch (error) {
  345. console.log("Error fetching Revenue API response:", error);
  346. if (error.name === 'SyntaxError') {
  347. console.log("Malformed JSON response. Verify the GP service output.");
  348. }
  349. return null;
  350. }
  351. } else {
  352. // gpServiceUrl = 'https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCPropertyTax/EstRevenue/GPServer/EstRevenue'
  353. const requestUrl = `https://erp.chennaicorporation.gov.in/pgr/external/mobileservice?serviceId=getGisRevenueData&` + queryParams;
  354. let apiResponse
  355. try {
  356. // setInterval(async () => {
  357. apiResponse = await esriRequest(requestUrl, { responseType: 'json' });
  358. // }, 3000);
  359. if (apiResponse.data.Message === 'Connection Failure') return [];
  360. const revenueData = apiResponse.data[0].Revenue;
  361. // Find the array of data that matches the key (Company, Profession, or Trade)
  362. const revenueTypeData = revenueData.find(item => Object.keys(item)[0] === taxType);
  363. // let resultData = fetchDueDetails(revenueTypeData[taxType], MisInput, 'PROPERTYTAX_NUMBER')
  364. // return resultData
  365. if (revenueTypeData[taxType].length > 0)
  366. return revenueTypeData[taxType]
  367. else return []
  368. // }, 3000);
  369. } catch (error) {
  370. console.log("Error fetching GP result data:", error);
  371. if (error.name === 'SyntaxError') {
  372. console.log("Malformed JSON response. Verify the GP service output.");
  373. }
  374. return null;
  375. }
  376. }
  377. }
  378. export const fetchBuildingTypeList = async (layer, query) => {
  379. const result = await layer.queryFeatures(query)
  380. if (result.features.length === 0) {
  381. return []// Exit the loop if no more features are returned
  382. }
  383. else {
  384. return result;
  385. }
  386. }
  387. export const fetchBuildingInputList = async (layer, query) => {
  388. const result = await layer.queryFeatures(query)
  389. if (result.features.length === 0) {
  390. return []// Exit the loop if no more features are returned
  391. }
  392. else {
  393. return result;
  394. }
  395. }
  396. export const fetchAllFeatures = async (layer, query) => {
  397. let allFeatures = [];
  398. const pageSize = 2000;
  399. let offset = 0;
  400. while (true) {
  401. query.start = offset;
  402. query.num = pageSize;
  403. const result = await layer.queryFeatures(query)
  404. if (result.features.length === 0) {
  405. break; // Exit the loop if no more features are returned
  406. }
  407. allFeatures = allFeatures.concat(result.features);
  408. offset += pageSize;
  409. // If the number of features returned is less than the page size, we've fetched all features
  410. if (result.features.length < pageSize) {
  411. break;
  412. }
  413. }
  414. return allFeatures;
  415. }