Skip to content

Commit 5292831

Browse files
Implementation & Fix: All form type postfunding update
1 parent e3cf9b4 commit 5292831

File tree

3 files changed

+202
-0
lines changed

3 files changed

+202
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
const db = require("../configs/mysql_config");
2+
const asyncHandler = require("../middlewares/asyncHandler");
3+
4+
//Fetch data from prefunding forms
5+
const getpf_landformData_sql = `SELECT
6+
forms.farmer_name,
7+
forms.spouse,
8+
forms.mcode,
9+
forms.hamlet,
10+
forms.panchayat,
11+
form_lands.revenue,
12+
forms.district,
13+
forms.block,
14+
form_lands.p_contribution,
15+
form_lands.f_contribution,
16+
files.passbook_postfunding,
17+
form_lands.verified_by,
18+
form_lands.total_area
19+
FROM
20+
forms
21+
LEFT JOIN
22+
form_lands ON forms.id = form_lands.form_id
23+
LEFT JOIN
24+
files ON forms.id = files.form_id
25+
WHERE
26+
forms.form_type = 1
27+
AND forms.id = ?`;
28+
29+
exports.getpf_landformData = asyncHandler(async (req, res) => {
30+
const connection = await db.getConnection();
31+
const form_id = req.query.form_id;
32+
33+
try {
34+
const [results] = await connection.execute(getpf_landformData_sql, [form_id]);
35+
//console.log(res);
36+
if (results.length > 0) {
37+
res.status(200);
38+
//console.log(results[0]);
39+
return res.json(results[0]);
40+
} else {
41+
return res.json(0);
42+
}
43+
} catch (err) {
44+
return res.status(500).json({ error: err.message });
45+
} finally {
46+
connection.release(); // Always release the connection
47+
}
48+
});
49+
50+
//Update postfunding data
51+
const updatepf_landformData_sql = `
52+
UPDATE form_lands
53+
LEFT JOIN forms ON form_lands.form_id = forms.id
54+
LEFT JOIN files ON forms.id = files.form_id
55+
SET
56+
form_lands.p_contribution = ?,
57+
form_lands.f_contribution = ?,
58+
form_lands.total_est = ?,
59+
form_lands.measured_by = "verifier-1",
60+
form_lands.total_area = ?,
61+
files.passbook_postfunding = "passbook.pdf"
62+
WHERE
63+
form_lands.form_id = ?
64+
AND forms.form_type = 1`;
65+
66+
exports.updatepf_landformData = asyncHandler(async (req, res) => {
67+
const connection = await db.getConnection();
68+
// const form_id = req.query.form_id;
69+
const pf_landformData = req.body;
70+
try {
71+
console.log(pf_landformData);
72+
console.log(pf_landformData.landDevelopment.pradanContribution);
73+
console.log(pf_landformData.landDevelopment.farmerContribution);
74+
console.log(pf_landformData.landDevelopment.totalEstimate);
75+
console.log(pf_landformData.landOwnership.totalArea);
76+
console.log(pf_landformData.bankDetails.pf_passbook);
77+
console.log(pf_landformData.basicDetails.form_id);
78+
const [results] = await connection.execute(updatepf_landformData_sql, [
79+
pf_landformData.landDevelopment.pradanContribution,
80+
pf_landformData.landDevelopment.farmerContribution,
81+
pf_landformData.landDevelopment.totalEstimate,
82+
pf_landformData.landDevelopment.totalArea,
83+
pf_landformData.basicDetails.form_id
84+
]);
85+
if (results.affectedRows > 0) {
86+
res.status(200).json("Received data successfully");
87+
return res.json(1);
88+
} else {
89+
return res.json(0);
90+
}
91+
} catch (err) {
92+
return res.status(500).json({ error: err.message });
93+
} finally {
94+
connection.release(); // Always release the connection
95+
}
96+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
const db = require("../configs/mysql_config");
2+
const asyncHandler = require("../middlewares/asyncHandler");
3+
4+
//Fetch data from prefunding forms
5+
const getpf_plantationformData_sql = ` SELECT
6+
forms.farmer_name,
7+
forms.spouse,
8+
forms.mcode,
9+
forms.hamlet,
10+
forms.panchayat,
11+
plantation_details.revenue,
12+
forms.district,
13+
forms.block,
14+
plantation_details.p_contribution,
15+
plantation_details.f_contribution,
16+
files.passbook_postfunding,
17+
plantation_details.verified_by,
18+
plantation_details.total_area,
19+
plantation_details.plantaions,
20+
plantation_details.nos,
21+
plantation_details.price,
22+
plantation_details.other_exp,
23+
plantation_details.tot_nos,
24+
plantation_details.tot_price
25+
FROM
26+
forms
27+
LEFT JOIN
28+
plantation_details ON forms.id = plantation_details.form_id
29+
LEFT JOIN
30+
files ON forms.id = files.form_id
31+
WHERE
32+
forms.form_type = 3
33+
AND forms.id = ?` ;
34+
35+
exports.getpf_plantationformData = asyncHandler(async (req, res) => {
36+
const connection = await db.getConnection();
37+
const form_id = req.query.form_id;
38+
39+
try {
40+
const [results] = await connection.execute(getpf_plantationformData_sql, [form_id]);
41+
42+
if (results.length > 0) {
43+
return res.json(results[0]);
44+
} else {
45+
return res.json(0);
46+
}
47+
} catch (err) {
48+
return res.status(500).json({ error: err.message });
49+
} finally {
50+
connection.release(); // Always release the connection
51+
}
52+
});
53+
54+
//Update postfunding data
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
const db = require("../configs/mysql_config");
2+
const asyncHandler = require("../middlewares/asyncHandler");
3+
4+
//Fetch data from prefunding forms
5+
const getpf_pondformData_sql = `SELECT
6+
forms.farmer_name,
7+
forms.spouse,
8+
forms.mcode,
9+
forms.hamlet,
10+
forms.panchayat,
11+
farm_pond_details.revenue,
12+
forms.district,
13+
forms.block,
14+
farm_pond_details.p_contribution,
15+
farm_pond_details.f_contribution,
16+
files.passbook_postfunding,
17+
farm_pond_details.verified_by,
18+
farm_pond_details.length,
19+
farm_pond_details.breadth,
20+
farm_pond_details.depth,
21+
farm_pond_details.volume,
22+
farm_pond_details.total_est
23+
FROM
24+
forms
25+
LEFT JOIN
26+
farm_pond_details ON forms.id = farm_pond_details.form_id
27+
LEFT JOIN
28+
files ON forms.id = files.form_id
29+
WHERE
30+
forms.form_type = 2
31+
AND forms.id = ? `;
32+
33+
exports.getpf_pondformData = asyncHandler(async (req, res) => {
34+
const connection = await db.getConnection();
35+
const form_id = req.query.form_id;
36+
37+
try {
38+
const [results] = await connection.execute(getpf_pondformData_sql, [form_id]);
39+
40+
if (results.length > 0) {
41+
return res.json(results[0]);
42+
} else {
43+
return res.json(0);
44+
}
45+
} catch (err) {
46+
return res.status(500).json({ error: err.message });
47+
} finally {
48+
connection.release(); // Always release the connection
49+
}
50+
});
51+
52+
//Update postfunding data

0 commit comments

Comments
 (0)