diff --git a/.classpath b/.classpath index bc93d16..83a3b6f 100644 --- a/.classpath +++ b/.classpath @@ -9,7 +9,6 @@ - @@ -29,12 +28,5 @@ - - - - - - - diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java b/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java index 4d36145..cdd8dc6 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/configuration/DataSourceConfig.java @@ -24,15 +24,14 @@ import java.util.Properties; @EnableTransactionManagement public class DataSourceConfig { - private static String host = "localhost:3306"; - private static String dbpassword = "root"; +// private static String host = "localhost:3306"; +// private static String dbpassword = "root"; // private static String dbpassword = "gccroot"; // AWS - // private static String host = - // "gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; - // private static String dbpassword = "gcc-facial-password"; + private static String host ="gcc-facial-db-instance-1.cf48eqcciziq.ap-south-1.rds.amazonaws.com:3306"; + private static String dbpassword = "gcc-facial-password"; ////////////////////////////// (For GCC APP) //////////////////////// @Configuration diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/APIContoller.java b/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/APIContoller.java index 906b2d5..0e9cfce 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/APIContoller.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/APIContoller.java @@ -19,7 +19,7 @@ import java.util.*; import java.util.stream.Collectors; @RestController -@RequestMapping("/gcc/works/api/estimates") +@RequestMapping("/gcc/api/works/estimates") public class APIContoller { @@ -901,4 +901,232 @@ public class APIContoller { return ResponseEntity.status(500).body(response); } } + + +//added by hariprasath + + @GetMapping("/getWorkDetailsById") + @ResponseBody + public List> getWorkDetailsById( + @RequestParam("estid") String estid) { + + return estimateService.getWorkDetailsById(estid); + } + + + @GetMapping("/addWorksQuestions") + @ResponseBody + public List> getQuestions( + @RequestParam("subcategory_id") int subcategoryId) { + + return estimateService.getQuestions(subcategoryId); + } + + @GetMapping("/subquestions") + @ResponseBody + public List> getSubQuestions( + @RequestParam("aam_id") int aamId) { + + return estimateService.getSubQuestions(aamId); + } + + @GetMapping("/getzones") + @ResponseBody + public List> getZones() { + + return estimateService.getZones(); + } + + @GetMapping("/getwards") + @ResponseBody + public List> getWards( + @RequestParam("zone") String zone) { + + return estimateService.getWards(zone); + } + + @GetMapping("/getroadsbyward") + @ResponseBody + public List> getRoadNamesByWard( + @RequestParam("ward") String ward) { + + return estimateService.getRoadNamesByWard(ward); + } + + @PostMapping("/addWorkDetails") + @ResponseBody + public Map addWorkDetails(@RequestBody Map request) { + + Map response = new HashMap<>(); + + try { + + List> details = (List>) request.get("details"); + + List> textDetails = (List>) request.get("textDetails"); + + Integer createdBy = Integer.valueOf(String.valueOf(request.get("createdBy"))); + + Integer estid = Integer.valueOf(String.valueOf(request.get("estid"))); + + Integer subCatId = Integer.valueOf(String.valueOf(request.get("subcategory_id"))); + + String estimateNo = String.valueOf(request.get("estimate_no")); + + // SUBCATEGORY 4 - DUPLICATE ROAD VALIDATION + + if (subCatId == 4) { + + String duplicateRoad = estimateService.checkDuplicateRoad(estid, textDetails); + + if (duplicateRoad != null) { + + response.put("status", false); + + response.put("message", "Already " + duplicateRoad + " has been mapped for this Estimation"); + + return response; + } + } + + estimateService.saveAllWorkDetails(createdBy, estid,estimateNo,subCatId , details, textDetails); + + response.put("status", true); + + response.put("message", "Work details saved successfully"); + + } catch (Exception e) { + + e.printStackTrace(); + + response.put("status", false); + + response.put("message", "Unable to save work details"); + } + + return response; + } + + @GetMapping("/getSavedDetails") + @ResponseBody + public List> getSavedWorkDetails( + @RequestParam("estid") int estid) { + + return estimateService.getSavedWorkDetails(estid); + } + + @PostMapping("/deleteSavedDetails") + @ResponseBody + public Map deleteSavedWorkDetails(@RequestParam("createdBy") int createdBy, + @RequestParam("estid") int estid, @RequestParam("ref_id") int refId) { + + try { + + return estimateService.deleteSavedWorkDetails(createdBy, estid, refId); + + } catch (Exception e) { + + e.printStackTrace(); + + Map response = new HashMap<>(); + response.put("status", false); + response.put("message", "Unable to remove work details"); + + return response; + } + } + + @GetMapping("/getEditDetails") + @ResponseBody + public List> getEditWorkDetails(@RequestParam("estid") int estid, + @RequestParam("ref_id") int refId, @RequestParam("subcategory_id") int subcategoryId) { + + return estimateService.getEditWorkDetails(estid, refId, subcategoryId); + } + + @PostMapping("/updateSavedDetails") + @ResponseBody + public Map updateSavedWorkDetails(@RequestBody Map request) { + + + + try { + + Integer estid = Integer.valueOf(String.valueOf(request.get("estid"))); + + Integer refId = Integer.valueOf(String.valueOf(request.get("ref_id"))); + + Integer subcategoryId = Integer.valueOf(String.valueOf(request.get("subcategory_id"))); + + Integer createdBy = Integer.valueOf(String.valueOf(request.get("createdBy"))); + + String estimateNo =String.valueOf(request.get("estimate_no")); + + List> details = (List>) request.get("details"); + + List> textDetails = (List>) request.get("textDetails"); + + /* + * Duplicate ROAD validation + */ + if (subcategoryId == 4) { + + String duplicateRoad = estimateService.checkDuplicateRoadForUpdate(estid, refId, textDetails); + + if (duplicateRoad != null) { + Map response = new HashMap<>(); + + response.put("status", false); + + response.put("message", "Already " + duplicateRoad + " present in Database"); + + return response; + } + } + + return estimateService.updateSavedWorkDetails(createdBy, estid, refId, estimateNo, subcategoryId, details,textDetails); + + + } catch (Exception e) { + + e.printStackTrace(); + Map response = new HashMap<>(); + + response.put("status", false); + + response.put("message", "Unable to update work details"); + return response; + } + + } + + + @GetMapping("/checkWorkProgress") + @ResponseBody + public Map checkWorkProgress(@RequestParam("estid") int estid, @RequestParam("ref_id") int refId) { + + Map response = new HashMap<>(); + + try { + + boolean started = estimateService.isWorkProgressStarted(estid, refId); + + response.put("status", true); + response.put("workStarted", started); + + if (started) { + response.put("message", "Work progress is started, Unable to edit or remove"); + } + + } catch (Exception e) { + + e.printStackTrace(); + + response.put("status", false); + response.put("message", "Unable to check work progress"); + } + + return response; + } + } diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/MainController.java b/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/MainController.java index 1957e3a..595b734 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/MainController.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/works/controller/MainController.java @@ -222,5 +222,27 @@ public class MainController { return BasePath + "project_status_update"; } + + @GetMapping("/addworks") + public String addworksWebPage( + Model model, + @RequestParam(value = "estid", required = false) String estid, + @RequestParam(value = "sub_category_id", required = false) Integer sub_category_id, + @RequestParam(value = "estimate_no", required = false) String estimate_no, + @RequestParam(value = "sub_category", required = false) String sub_category) + { + + String LoginUserId = LoginUserInfo.getLoginUserId(); + + model.addAttribute("LoginUserId", LoginUserId); + model.addAttribute("estid", estid); + model.addAttribute("sub_category_id", sub_category_id); + model.addAttribute("estimate_no", estimate_no); + model.addAttribute("sub_category", sub_category); + + + return BasePath + "addworkspage"; + } + } diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/ERPEstimateService.java b/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/ERPEstimateService.java index 965f334..cc190da 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/ERPEstimateService.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/ERPEstimateService.java @@ -240,8 +240,8 @@ public class ERPEstimateService { String loginId, String finYear, String oValue) { StringBuilder sql = new StringBuilder("SELECT ew.`estid`, ew.`estimate_no`, DATE(ew.`estimate_date`) AS `estimate_date`," - + "ew.`zone`, ew.`ward`, dm.dept_name as `department`, wm.name as `category`, " - + "trim(tm.description) as `sub_category`, ew.`project_name`, ew.`estimation_amount`, ew.`est_val_with_oh` FROM erp_works ew " + + "ew.`zone`, ew.`ward`, dm.dept_name as `department`, wm.name as `category`, ew.`sub_category` as sub_category_id, " + + "trim(tm.description) as `sub_category`, ew.`project_name`, ew.`estimation_amount`, ew.`est_val_with_oh` FROM works_details ew " + "LEFT JOIN department_master dm ON dm.id = ew.department " + "LEFT JOIN workstype_master wm ON wm.id = ew.category " + "LEFT JOIN typeofwork_master tm ON tm.id = ew.sub_category"); diff --git a/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/EstimateService.java b/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/EstimateService.java index bd5d631..a40c68b 100644 --- a/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/EstimateService.java +++ b/src/main/java/in/gov/chennaicorporation/gccoffice/works/service/EstimateService.java @@ -3,6 +3,8 @@ package in.gov.chennaicorporation.gccoffice.works.service; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; +import java.net.URI; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -35,7 +37,11 @@ import org.springframework.jdbc.support.GeneratedKeyHolder; import org.springframework.jdbc.support.KeyHolder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.client.RestTemplate; import org.springframework.web.multipart.MultipartFile; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; @Service public class EstimateService { @Autowired @@ -174,14 +180,16 @@ public class EstimateService { String remarks_txt = remarks; + int nonErp=1; + // ✅ SQL Query - String sqlQuery = "INSERT INTO gcc_works_status.non_erp_works (estimate_no, estimate_date, zone, ward, isiconic, project_name, location, " + + String sqlQuery = "INSERT INTO gcc_works_status.works_details (estimate_no, estimate_date, zone, ward, isiconic, project_name, location, " + "department, contractor_name, contractor_period, fund_source, scheme, category, sub_category, " + "estimation_amount, technical_sanction_date, admin_sanction_date, admin_sanction_file, tender_called_date, tender_finalized_date, " + "loa_date, loa_file, agreement_date, agreement_file, work_order_date, work_order_file, work_commenced_date, reason, remarks," - + "project_type, govt_funded_project, special_category, filenumber) " + + + "project_type, govt_funded_project, special_category, filenumber,nonerp) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, " - + "?, ?, ?, ?)"; + + "?, ?, ?, ?, ?)"; KeyHolder keyHolder = new GeneratedKeyHolder(); @@ -220,6 +228,7 @@ public class EstimateService { ps.setString(31, govtfund); ps.setString(32, specialcat); ps.setString(33, filenumber); + ps.setInt(34, nonErp); return ps; }, keyHolder); @@ -238,7 +247,7 @@ public class EstimateService { // ✅ Construct SQL Query with Actual Values (For Logging) String formattedSql = String.format( - "INSERT INTO gcc_works_status.non_erp_works (estimate_no, estimate_date, zone, ward, isiconic, project_name, location, " + + "INSERT INTO gcc_works_status.works_details (estimate_no, estimate_date, zone, ward, isiconic, project_name, location, " + "department, contractor_name, contractor_period, fund_source, scheme, category, sub_category, " + "estimation_amount, technical_sanction_date, admin_sanction_date, admin_sanction_file, tender_called_date, tender_finalized_date, " + "loa_date, loa_file, agreement_date, agreement_file, work_order_date, work_order_file, work_commenced_date, reason, remarks) " + @@ -258,7 +267,8 @@ public class EstimateService { @Transactional public boolean updateESTno(int estid ,String estNo) { - String sqlQuery = "UPDATE `non_erp_works` SET `estimate_no`='"+estNo+"' WHERE `estid`='"+estid+"'"; +// String sqlQuery = "UPDATE `non_erp_works` SET `estimate_no`='"+estNo+"' WHERE `estid`='"+estid+"'"; + String sqlQuery = "UPDATE `works_details` SET `estimate_no`='"+estNo+"' WHERE `estid`='"+estid+"'"; jdbcTemplate.update(sqlQuery); return true; } @@ -325,10 +335,10 @@ public class EstimateService { if(!where.equals("")) { where = " WHERE "+ where; } - + // table changed from erp_works to works_details String sql = "SELECT ew.estid, ew.estimate_no, ew.estimate_date, ew.zone, ew.ward, ew.project_name, ew.location, " + " dm.dept_name, ew.contractor_name, ew.contractor_period, fm.name as fund_source, sm.name as scheme, " + - " wm.name as category, tm.description as sub_category FROM gcc_works_status.erp_works ew " + + " wm.name as category, tm.description as sub_category FROM gcc_works_status.works_details ew " + " left join gcc_works_status.department_master dm on dm.id = ew.department " + " left join gcc_works_status.workstype_master wm on wm.id = ew.category " + " left join gcc_works_status.typeofwork_master tm on tm.id = ew.sub_category " + @@ -371,7 +381,7 @@ public class EstimateService { } public List> getSubCategoryList() { - String sql = "SELECT * FROM gcc_works_status.typeofwork_master order by DESCRIPTION asc"; + String sql = "SELECT * FROM gcc_works_status.typeofwork_master WHERE isactive=1 order by DESCRIPTION asc"; // Fetch the details from the database as a Map List> result = jdbcTemplate.queryForList(sql); @@ -397,8 +407,8 @@ public class EstimateService { public int updateEstimateDetails(Map updatedDetails, String sanFilePath, String loaFilePath, String agreementFilePath, String workOrderFilePath) throws IOException { - // ✅ Base SQL query - StringBuilder sql = new StringBuilder("UPDATE gcc_works_status.erp_works SET " + // ✅ Base SQL query - table changed from erp_works to works_details + StringBuilder sql = new StringBuilder("UPDATE gcc_works_status.works_details SET " + "estimate_date = ?, zone = ?, ward = ?, project_name = ?, location = ?, " + "isiconic = ?, department = ?, contractor_name = ?, contractor_period = ?, " + "fund_source = ?, scheme = ?, category = ?, sub_category = ?, estimation_amount = ?, " @@ -540,7 +550,8 @@ public class EstimateService { //model service public List> fetchEstimateByCode(String estimateCode) { - String query = "SELECT * FROM gcc_works_status.erp_works WHERE estimate_no=?"; +// String query = "SELECT * FROM gcc_works_status.erp_works WHERE estimate_no=?"; + String query = "SELECT * FROM gcc_works_status.works_details WHERE estimate_no=?"; return jdbcTemplate.queryForList(query, estimateCode); } @@ -570,7 +581,8 @@ public class EstimateService { } public List getAllWorksDetails() { - String sql = "SELECT distinct estimate_no FROM gcc_works_status.erp_works"; +// String sql = "SELECT distinct estimate_no FROM gcc_works_status.erp_works"; + String sql = "SELECT distinct estimate_no FROM gcc_works_status.works_details"; return jdbcTemplate.queryForList(sql, String.class); } @@ -604,7 +616,7 @@ public class EstimateService { String loaFile, String agreementDate, String agreementFile, String workOrderDate, String workOrderFile, String workCommDate) { - String sql = "INSERT INTO gcc_works_status.erp_works (estimate_no, estimate_date, zone, ward, project_name, location, " + + String sql = "INSERT INTO gcc_works_status.works_details (estimate_no, estimate_date, zone, ward, project_name, location, " + "department, contractor_name, contractor_period, fund_source, scheme, category, sub_category, " + "estimation_amount, technical_sanction_date, admin_sanction_date, admin_sanction_file, tender_called_date, tender_finalized_date, loa_date, " + "loa_file, agreement_date, agreement_file, work_order_date, work_order_file, work_commenced_date, isiconic) " + @@ -775,7 +787,9 @@ public class EstimateService { public List> getAllNonERPWorks(String loginId) { String accessData = getUserAccess(loginId); - String where=""; +// String where=""; + + String where="new.`nonerp`=1 "; // Split the string using "_" String[] parts = accessData.split("_"); @@ -796,10 +810,10 @@ public class EstimateService { if(!where.equals("")) { where = " WHERE "+ where; } - - String sql = "SELECT new.estid, new.estimate_no, new.estimate_date, new.zone, new.ward, new.project_name, new.location, new.filenumber, new.estimation_amount, " + + // table changed from non_erp_works to works_details + String sql = "SELECT new.estid, new.estimate_no, new.estimate_date, new.zone, new.ward, new.project_name, new.location, new.filenumber, new.estimation_amount,new.sub_category as sub_category_id, " + " dm.dept_name, new.contractor_name, new.contractor_period, fm.name as fund_source, sm.name as scheme, " + - " wm.name as category, tm.description as sub_category FROM gcc_works_status.non_erp_works new " + + " wm.name as category, tm.description as sub_category FROM gcc_works_status.works_details new " + " left join gcc_works_status.department_master dm on dm.id = new.department " + " left join gcc_works_status.workstype_master wm on wm.id = new.category " + " left join gcc_works_status.typeofwork_master tm on tm.id = new.sub_category " + @@ -811,7 +825,7 @@ public class EstimateService { public Map getERPEstimateDetails(String estimateNo) { - + // table changed from non_erp_works to works_details String sql = "select ew.estimate_no, ew.estimate_date, ew.zone, ew.ward, ew.project_name, ew.location, ew.department, ew.contractor_name, " + "ew.contractor_period, ew.estimation_amount as est_amount, ew.technical_sanction_date as tech_sanc_date, ew.admin_sanction_date as admin_sanc_date," + "ew.tender_called_date as tender_call_date, ew.tender_called_date as tender_fin_date, ew.loa_date, ew.agreement_date, ew.work_order_date, " + @@ -819,12 +833,12 @@ public class EstimateService { "ew.isiconic as iconic_project, dm.dept_name, ew.fund_source as fundsource, fm.name as fund_source, " + "ew.scheme as schemeid, sm.name as scheme, ew.category as categoryid, wm.name as category, ew.sub_category as subcategoryid, " + "tm.description as sub_category " + - "from gcc_works_status.erp_works ew " + + "from gcc_works_status.works_details ew " + " left join gcc_works_status.department_master dm on dm.id = ew.department " + " left join gcc_works_status.workstype_master wm on wm.id = ew.category " + " left join gcc_works_status.typeofwork_master tm on tm.id = ew.sub_category " + " left join gcc_works_status.fundsource_master fm on fm.id = ew.fund_Source " + - " left join gcc_works_status.scheme_master sm on sm.id = ew.scheme where ew.estimate_no = ? LIMIT 100"; + " left join gcc_works_status.scheme_master sm on sm.id = ew.scheme where ew.estimate_no = ? AND LIMIT 100 "; // Fetch the details from the database as a Map List> details = jdbcTemplate.queryForList(sql, estimateNo); @@ -837,7 +851,7 @@ public class EstimateService { } public Map getNonERPEstimateDetails(String estimateNo) { - + // table changed from non_erp_works to works_details String sql = "select ew.estimate_no, ew.estimate_date, ew.zone, ew.ward, ew.project_name, ew.location, ew.department, ew.contractor_name, " + "ew.contractor_period, ew.estimation_amount as est_amount, ew.technical_sanction_date as tech_sanc_date, ew.admin_sanction_date as admin_sanc_date," + "ew.tender_called_date as tender_call_date, ew.tender_called_date as tender_fin_date, ew.loa_date, ew.agreement_date, ew.work_order_date, " + @@ -845,7 +859,7 @@ public class EstimateService { "ew.isiconic as iconic_project, dm.dept_name, ew.fund_source as fundsource, fm.name as fund_source, " + "ew.scheme as schemeid, sm.name as scheme, ew.category as categoryid, wm.name as category, ew.sub_category as subcategoryid, ew.reason, ew.remarks, " + "tm.description as sub_category, ew.`project_type`, ew.`govt_funded_project`, ew.`special_category`, ew.`filenumber` " + - "from gcc_works_status.non_erp_works ew " + + "from gcc_works_status.works_details ew " + " left join gcc_works_status.department_master dm on dm.id = ew.department " + " left join gcc_works_status.workstype_master wm on wm.id = ew.category " + " left join gcc_works_status.typeofwork_master tm on tm.id = ew.sub_category " + @@ -864,15 +878,33 @@ public class EstimateService { public int updateNonERPEstimateDetails(Map updatedDetails, String sanFilePath, String loaFilePath, String agreementFilePath, String workOrderFilePath) throws IOException { + + + + String estimateNo = + String.valueOf(updatedDetails.get("estimate_no")); + + System.out.println("estimateNo>>>>>>"+estimateNo); + + Map existingData = + getExistingNonErpEstimate(estimateNo); - // ✅ Base SQL query - StringBuilder sql = new StringBuilder("UPDATE gcc_works_status.non_erp_works SET " + if (existingData == null || existingData.isEmpty()) { + return 0; + } + + // 2. Save OLD data + saveNonErpEstimateLog(estimateNo); + + + // ✅ Base SQL query - table changed from non_erp_works to works_details + StringBuilder sql = new StringBuilder("UPDATE gcc_works_status.works_details SET " + "estimate_date = ?, zone = ?, ward = ?, project_name = ?, location = ?, " + "isiconic = ?, department = ?, contractor_name = ?, contractor_period = ?, " + "fund_source = ?, scheme = ?, category = ?, sub_category = ?, estimation_amount = ?, " + "technical_sanction_date = ?, admin_sanction_date = ?, tender_called_date = ?, tender_finalized_date = ?, " + "loa_date = ?, agreement_date = ?, work_order_date = ?, work_commenced_date = ?, " - + "project_type=?, govt_funded_project=?, special_category=?, filenumber=? "); + + "project_type=?, govt_funded_project=?, special_category=?, filenumber=? ,update_date = NOW()"); // ✅ Dynamically append file updates if new files are provided List params = new ArrayList<>(Arrays.asList( @@ -945,6 +977,76 @@ public class EstimateService { return jdbcTemplate.update(sql.toString(), params.toArray()); } + + +private Map getExistingNonErpEstimate(String estimateNo) { + + String sql = "SELECT wd.estid, wd.nonerp, wd.estimate_no, wd.estimate_date, wd.zone, wd.ward, wd.project_name, " + + " wd.location, wd.department, wd.contractor_name, wd.contractor_period, " + + " wd.fund_source, wd.scheme, wd.category, wd.sub_category, wd.estimation_amount, " + + " wd.technical_sanction_date, wd.admin_sanction_date, wd.admin_sanction_file, wd.tender_called_date," + + " wd.tender_finalized_date, wd.loa_date, wd.loa_file, " + + " wd.agreement_date, wd.agreement_file, wd.work_order_date, wd.work_order_file, wd.work_commenced_date, " + + " wd.update_status, wd.reason, wd.remarks, wd.project_type, " + + " wd.govt_funded_project, wd.special_category, wd.filenumber, wd.est_val_with_oh, " + + " wd.works_data_erp_id, wd.percentage, wd.est_type, wd.est_sub_cat_2, wd.project_id, " + + " wd.project_code, wd.type_2, wd.type_2_child, " + + " wd.isactive, wd.isdelete, wd.isiconic, wd.cdate " + + " FROM gcc_works_status.works_details wd " + + " where wd.estimate_no = ? and wd.isactive = 1 and wd.isdelete = 0 AND wd.nonerp = 1"; + + List> result = + jdbcTemplate.queryForList(sql, estimateNo); + + if (result.isEmpty()) { + return null; + } + + return result.get(0); + } + + + private void saveNonErpEstimateLog(String estimateNo) { + + String sql = + "INSERT INTO gcc_works_status.works_details_log " + + "(works_details_estid, nonerp, estimate_no, estimate_date, zone, ward, " + + "project_name, location, department, contractor_name, " + + "contractor_period, fund_source, scheme, category, " + + "sub_category, estimation_amount, technical_sanction_date, " + + "admin_sanction_date, admin_sanction_file, tender_called_date, " + + "tender_finalized_date, loa_date, loa_file, agreement_date, " + + "agreement_file, work_order_date, work_order_file, " + + "work_commenced_date, update_status, reason, remarks, " + + "project_type, govt_funded_project, special_category, " + + "filenumber, est_val_with_oh, works_data_erp_id, percentage, " + + "est_type, est_sub_cat_2, project_id, project_code, type_2, " + + "type_2_child, isactive, isdelete, isiconic, cdate) " + + + "SELECT " + + "estid, nonerp, estimate_no, estimate_date, zone, ward, " + + "project_name, location, department, contractor_name, " + + "contractor_period, fund_source, scheme, category, " + + "sub_category, estimation_amount, technical_sanction_date, " + + "admin_sanction_date, admin_sanction_file, tender_called_date, " + + "tender_finalized_date, loa_date, loa_file, agreement_date, " + + "agreement_file, work_order_date, work_order_file, " + + "work_commenced_date, update_status, reason, remarks, " + + "project_type, govt_funded_project, special_category, " + + "filenumber, est_val_with_oh, works_data_erp_id, percentage, " + + "est_type, est_sub_cat_2, project_id, project_code, type_2, " + + "type_2_child, isactive, isdelete, isiconic, cdate " + + + "FROM gcc_works_status.works_details " + + "WHERE estimate_no = ? " + + "AND nonerp = 1 " + + "AND isactive = 1 " + + "AND isdelete = 0 " + + "LIMIT 1"; + + jdbcTemplate.update(sql, estimateNo); + } + ///// Balaji public List> getestimateworkdetailsById(String estid) { @@ -1056,6 +1158,8 @@ public class EstimateService { String fundSourceId = getFundSourceId(fundSource); String schemeId = getSchemeId(scheme); + int cpvalue=Integer.parseInt(contractorPeriod); + techSancDate = normalizeDate(techSancDate); agreementDate = normalizeDate(agreementDate); adminSancDate = normalizeDate(adminSancDate); @@ -1065,7 +1169,8 @@ public class EstimateService { workOrderDate = normalizeDate(workOrderDate); workCommDate = normalizeDate(workCommDate); - String sql = "INSERT INTO `gcc_works_status`.`erp_works` (estimate_no, estimate_date, zone, ward, project_name, location, " + + // table changed from non_erp_works to works_details + String sql = "INSERT INTO `gcc_works_status`.`works_details` (estimate_no, estimate_date, zone, ward, project_name, location, " + "department, contractor_name, contractor_period, fund_source, scheme, category, sub_category, " + "estimation_amount, technical_sanction_date, admin_sanction_date, admin_sanction_file, tender_called_date, " + "tender_finalized_date, loa_date, " + @@ -1079,7 +1184,7 @@ public class EstimateService { int result = jdbcTemplate.update(sql, estimateNo, estimateDate, zone, ward, projectName, - location, departmentId, contractorName, contractorPeriod, fundSourceId, + location, departmentId, contractorName, cpvalue, fundSourceId, schemeId, categoryId, subCategoryId, estAmount, techSancDate, adminSancDate, admSanFile, tenderCallDate, tenderFinDate, loaDate, loaFile, agreementDate, agreementFile, workOrderDate, workOrderFile, @@ -1088,9 +1193,9 @@ public class EstimateService { updateWorksDataErpStatus(works_data_erp_id); - runSqlScript(); +// runSqlScript(); -- commented because this will be configured through add works option for all the sub category - String logsql = "INSERT INTO `gcc_works_status`.`erp_works` (estimate_no, estimate_date, zone, ward, project_name, location, " + + String logsql = "INSERT INTO `gcc_works_status`.`works_details` (estimate_no, estimate_date, zone, ward, project_name, location, " + "department, contractor_name, contractor_period, fund_source, scheme, category, sub_category, " + "estimation_amount, technical_sanction_date, admin_sanction_date, admin_sanction_file, tender_called_date, " + "tender_finalized_date, loa_date, " + @@ -1501,6 +1606,22 @@ public class EstimateService { String loaFile, String agreementDate, String agreementFile, String workOrderDate, String workOrderFile, String workCommDate, String loginid, String projecttype, String govtfund, String specialcat) { + + + + Map existingData = + getExistingEstimate(estid); + + System.out.println("existingData"+existingData); + + + if (existingData == null || existingData.isEmpty()) { + return 0; + } + + // save log table(work_details_log) + saveEstimateLog(estid); + // Normalize blank date fields to null techSancDate = normalizeDate(techSancDate); @@ -1516,11 +1637,11 @@ public class EstimateService { StringBuilder fileQuery = new StringBuilder(); List params = new ArrayList<>(); - // Base SQL - String sql = "UPDATE `gcc_works_status`.`erp_works` SET " + // Base SQL - table changed from non_erp_works to works_details + String sql = "UPDATE `gcc_works_status`.`works_details` SET " + "technical_sanction_date=?, admin_sanction_date=?, tender_called_date=?, " + "tender_finalized_date=?, loa_date=?, agreement_date=?, work_order_date=?, work_commenced_date=?, " - + "isiconic=?, project_type=?, govt_funded_project=?, special_category=?"; + + "isiconic=?, project_type=?, govt_funded_project=?, special_category=?,update_date = NOW()"; // Add base parameters Collections.addAll(params, techSancDate, adminSancDate, tenderCallDate, tenderFinDate, @@ -1559,7 +1680,80 @@ public class EstimateService { return result; } + + + private Map getExistingEstimate(String estid) { + + String sql = "SELECT wd.estid, wd.nonerp, wd.estimate_no, wd.estimate_date, wd.zone, wd.ward, wd.project_name, " + + " wd.location, wd.department, wd.contractor_name, wd.contractor_period, " + + " wd.fund_source, wd.scheme, wd.category, wd.sub_category, wd.estimation_amount, " + + " wd.technical_sanction_date, wd.admin_sanction_date, wd.admin_sanction_file, wd.tender_called_date," + + " wd.tender_finalized_date, wd.loa_date, wd.loa_file, " + + " wd.agreement_date, wd.agreement_file, wd.work_order_date, wd.work_order_file, wd.work_commenced_date, " + + " wd.update_status, wd.reason, wd.remarks, wd.project_type, " + + " wd.govt_funded_project, wd.special_category, wd.filenumber, wd.est_val_with_oh, " + + " wd.works_data_erp_id, wd.percentage, wd.est_type, wd.est_sub_cat_2, wd.project_id, " + + " wd.project_code, wd.type_2, wd.type_2_child, " + + " wd.isactive, wd.isdelete, wd.isiconic, wd.cdate " + + " FROM gcc_works_status.works_details wd " + + " where wd.estid = ? and wd.isactive = 1 and wd.isdelete = 0 AND wd.nonerp = 0"; + + List> result = + jdbcTemplate.queryForList(sql, estid); + + if (result.isEmpty()) { + return null; + } + + return result.get(0); + } + + + + + private void saveEstimateLog(String estid) { + + String sql = + " INSERT INTO gcc_works_status.works_details_log " + + " (works_details_estid, nonerp, estimate_no, estimate_date, zone, ward, " + + " project_name, location, department, contractor_name, " + + " contractor_period, fund_source, scheme, category, " + + " sub_category, estimation_amount, technical_sanction_date, " + + " admin_sanction_date, admin_sanction_file, tender_called_date, " + + " tender_finalized_date, loa_date, loa_file, agreement_date, " + + " agreement_file, work_order_date, work_order_file, " + + " work_commenced_date, update_status, reason, remarks, " + + " project_type, govt_funded_project, special_category, " + + " filenumber, est_val_with_oh, works_data_erp_id, percentage, " + + " est_type, est_sub_cat_2, project_id, project_code, type_2, " + + " type_2_child, isactive, isdelete, isiconic, cdate) " + + + + " SELECT " + + " estid, nonerp, estimate_no, estimate_date, zone, ward, " + + " project_name, location, department, contractor_name, " + + " contractor_period, fund_source, scheme, category, " + + " sub_category, estimation_amount, technical_sanction_date, " + + " admin_sanction_date, admin_sanction_file, tender_called_date, " + + " tender_finalized_date, loa_date, loa_file, agreement_date, " + + " agreement_file, work_order_date, work_order_file, " + + " work_commenced_date, update_status, reason, remarks, " + + " project_type, govt_funded_project, special_category, " + + " filenumber, est_val_with_oh, works_data_erp_id, percentage, " + + " est_type, est_sub_cat_2, project_id, project_code, type_2, " + + " type_2_child, isactive, isdelete, isiconic, cdate " + + " FROM gcc_works_status.works_details " + + " WHERE estid = ? " + + " AND isactive = 1 " + + " AND isdelete = 0 AND nonerp = 0 "; + + jdbcTemplate.update(sql, estid); + } + public List> getUserEstWorkDetailsById(String estid) { + + //table changed from non_erp_works to works_details + String sql = "SELECT ew.`estid`, ew.`estimate_no`, ew.`estimate_date`, ew.`zone`, ew.`ward`, " + "ew.`project_name`, ew.`location`, ew.`contractor_name`, ew.`contractor_period`, " + "fm.`name` AS `fund_source`, sm.`name` AS `scheme`, " @@ -1574,7 +1768,7 @@ public class EstimateService { + "ew.`works_data_erp_id`, ew.`percentage`, ew.`project_type`, ew.`govt_funded_project`, ew.`special_category`, " + "dm.dept_name as `department`, wm.name as `category`, " + "trim(tm.description) as `sub_category` " - + "FROM erp_works ew " + + "FROM works_details ew " + "LEFT JOIN department_master dm ON dm.id = ew.department " + "LEFT JOIN workstype_master wm ON wm.id = ew.category " + "LEFT JOIN typeofwork_master tm ON tm.id = ew.sub_category " @@ -1690,4 +1884,1609 @@ public class EstimateService { return jdbcTemplate.update(sql, pid, feedback, file, inby); } + + + // added by hariprasath + + public List> getWorkDetailsById(String estid) { + + String sql = + "SELECT " + + "wd.`estid`, " + + "wd.`nonerp`, " + + "wd.`estimate_no`, " + + "wd.`estimate_date`, " + + "wd.`zone`, " + + "wd.`ward`, " + + "wd.`project_name`, " + + "wd.`location`, " + + "wd.`contractor_name`, " + + "wd.`contractor_period`, " + + "fm.`name` AS `fund_source`, " + + "sm.`name` AS `scheme`, " + + "wd.`estimation_amount`, " + + "wd.`est_val_with_oh`, " + + "wd.`technical_sanction_date`, " + + "wd.`admin_sanction_date`, " + + "wd.`tender_called_date`, " + + "wd.`tender_finalized_date`, " + + "wd.`loa_date`, " + + "wd.`agreement_date`, " + + "wd.`work_order_date`, " + + "CONCAT('" + fileBaseUrl+ "/gcc/files', wd.`admin_sanction_file`) AS `admin_sanction_file`, " + + "CONCAT('" + fileBaseUrl+ "/gcc/files', wd.`agreement_file`) AS `agreement_file`, " + + "CONCAT('" + fileBaseUrl + "/gcc/files', wd.`loa_file`) AS `loa_file`, " + + "CONCAT('" + fileBaseUrl+ "/gcc/files', wd.`work_order_file`) AS `work_order_file`, " + + "wd.`work_commenced_date`, " + + "wd.`update_status`, " + + "wd.`isiconic`, " + + "wd.`works_data_erp_id`, " + + "wd.`percentage`, " + + "wd.`project_type`, " + + "wd.`govt_funded_project`, " + + "wd.`special_category`, " + + "dm.`dept_name` AS `department`, " + + "wm.`name` AS `category`, " + + "TRIM(tm.`description`) AS `sub_category` " + + + "FROM `works_details` wd " + + + "LEFT JOIN department_master dm ON dm.id = wd.`department` " + + "LEFT JOIN workstype_master wm ON wm.id = wd.`category` " + + "LEFT JOIN typeofwork_master tm ON tm.id = wd.`sub_category` " + + "LEFT JOIN scheme_master sm ON sm.id = wd.`scheme` " + + "LEFT JOIN fundsource_master fm ON fm.id = wd.`fund_source` " + + + "WHERE wd.`estid` = ? " + + "AND wd.`isactive` = 1 " + + "AND wd.`isdelete` = 0 " + + "LIMIT 1"; + + return jdbcTemplate.queryForList(sql, estid); + } + + public List> getQuestions(int subcategoryId) { + + String questionSql = """ + SELECT + id, + subcategory_id, + issub, + question_name, + answer_type, + ismandatory, + allow_zero, + orderby, + remarks, + input_source, + api_name, + isactive, + isdelete + FROM addworks_question_master + WHERE subcategory_id = ? + AND issub = 0 + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + List> questions = jdbcTemplate.queryForList(questionSql, subcategoryId); + + String answerSql = """ + SELECT + id, + question_id, + answer, + orderby, + remarks + FROM addworks_answer_master + WHERE question_id = ? + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + for (Map question : questions) { + + int questionId = ((Number) question.get("id")).intValue(); + + String inputSource = String.valueOf(question.get("input_source")); + + String answerType = String.valueOf(question.get("answer_type")); + + if ("MASTER".equalsIgnoreCase(inputSource) + && ("radio".equalsIgnoreCase(answerType) || "dropdown".equalsIgnoreCase(answerType))) { + + List> answers = jdbcTemplate.queryForList(answerSql, questionId); + + question.put("answers", answers); + + } else { + + question.put("answers", new ArrayList>()); + } + } + + return questions; + } + + public List> getSubQuestions(int aamId) { + + String questionSql = """ + SELECT + aqm.id, + aqm.subcategory_id, + aqm.issub, + aqm.question_name, + aqm.answer_type, + aqm.ismandatory, + aqm.allow_zero, + aqm.orderby, + aqm.remarks, + aqm.isactive, + aqm.isdelete, + aqm.input_source, + aqm.api_name + FROM addworks_subquestion_mapping asm + INNER JOIN addworks_question_master aqm + ON aqm.id = asm.aqm_id + WHERE asm.aam_id = ? + AND asm.isactive = 1 + AND asm.isdelete = 0 + AND aqm.isactive = 1 + AND aqm.isdelete = 0 + ORDER BY aqm.orderby + """; + + List> questions = jdbcTemplate.queryForList(questionSql, aamId); + + String answerSql = """ + SELECT + id, + question_id, + answer, + orderby, + remarks + FROM addworks_answer_master + WHERE question_id = ? + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + for (Map question : questions) { + + int questionId = ((Number) question.get("id")).intValue(); + + String inputSource = String.valueOf(question.get("input_source")); + + String answerType = String.valueOf(question.get("answer_type")); + + if ("MASTER".equalsIgnoreCase(inputSource) + && ("radio".equalsIgnoreCase(answerType) || "dropdown".equalsIgnoreCase(answerType))) { + + List> answers = jdbcTemplate.queryForList(answerSql, questionId); + + question.put("answers", answers); + + } else { + + question.put("answers", new ArrayList>()); + } + } + + return questions; + } + + public List> getZones() { + + String sql = """ + SELECT DISTINCT zone + FROM zones_wards_master + WHERE zone IS NOT NULL + AND zone <> '' + ORDER BY zone + """; + + return jdbcTemplate.queryForList(sql); + } + + public List> getWards(String zone) { + + String sql = """ + SELECT DISTINCT ward + FROM zones_wards_master + WHERE zone = ? + AND ward IS NOT NULL + AND ward <> '' + ORDER BY ward + """; + + return jdbcTemplate.queryForList(sql, zone); + } + + public List> getRoadNamesByWard(String ward) { + try { + String encodedWard = URLEncoder.encode("'"+ ward +"'", StandardCharsets.UTF_8.toString()); + String url = "https://gisgcc.chennaicorporation.gov.in/server/rest/services/GCCDepts/EDPMobile2025/FeatureServer/0/query" + + "?where=new_ward%3D" + encodedWard + + "&fullText=&objectIds=&time=&geometry=&geometryType=esriGeometryPoint&inSR=4326&defaultSR=4326&spatialRel=esriSpatialRelIntersects&distance=&units=esriSRUnit_Meter&relationParam=" + + "&outFields=road_id%2Croad_name%2Clocality%2Carea_name%2Ctype&returnGeometry=false" + + "&maxAllowableOffset=&geometryPrecision=&outSR=&havingClause=&gdbVersion=&historicMoment=&returnDistinctValues=false&returnIdsOnly=false&returnCountOnly=false&returnExtentOnly=false&orderByFields=&groupByFieldsForStatistics=&outStatistics=&returnZ=false&returnM=false&multipatchOption=xyFootprint&resultOffset=&resultRecordCount=&returnTrueCurves=false&returnExceededLimitFeatures=false&quantizationParameters=&returnCentroid=false&returnEnvelope=false&timeReferenceUnknownClient=false&maxRecordCountFactor=&sqlFormat=none&resultType=&featureEncoding=esriDefault&datumTransformation=&cacheHint=false" + + "&f=geojson"; + + //System.out.println("url=="+url); + + RestTemplate restTemplate = new RestTemplate(); + String responseBody = restTemplate.getForObject(URI.create(url), String.class); + + ObjectMapper objectMapper = new ObjectMapper(); + JsonNode root = objectMapper.readTree(responseBody); + JsonNode features = root.path("features"); + + List> roadList = new ArrayList<>(); + if (features.isArray()) { + for (JsonNode feature : features) { + JsonNode props = feature.path("properties"); + String roadId = props.path("road_id").asText(); + String roadName = props.path("road_name").asText(); + String locality = props.path("locality").asText(); + String areaName = props.path("area_name").asText(); + String type = props.path("type").asText(); + + Map roadInfo = new HashMap<>(); + roadInfo.put("road_id", roadId); + roadInfo.put("road_name", roadName); + roadInfo.put("locality", locality); + roadInfo.put("area_name", areaName); + roadInfo.put("type", type); + + roadList.add(roadInfo); + } + } + return roadList; + + } catch (Exception e) { + e.printStackTrace(); + return Collections.emptyList(); + } + } + + @Transactional + public void saveAllWorkDetails(Integer createdBy, Integer estid, String estimateNo,Integer subCatId, List> details, + List> textDetails) { + + if (details != null) { + + for (Map item : details) { + + saveDetails(item, createdBy, estid); + } + } + + if (textDetails != null) { + + for (Map item : textDetails) { + + saveTextDetails(item, createdBy, estid); + } + } + + Set refIds = new LinkedHashSet<>(); + + if (details != null) { + + for (Map item : details) { + + if (item.get("ref_id") != null) { + + Integer refId = + Integer.valueOf( + String.valueOf(item.get("ref_id")) + ); + + refIds.add(refId); + } + } + } + + if (textDetails != null) { + + for (Map item : textDetails) { + + if (item.get("ref_id") != null) { + + Integer refId = + Integer.valueOf( + String.valueOf(item.get("ref_id")) + ); + + refIds.add(refId); + } + } + } + + + for (Integer refId : refIds) { + /* Insert ERP task question_id = NULL ans_id = NULL */ + + insertErpWorksTask(estid,refId,estimateNo,subCatId); + + /* Create stages for this particular ref_id */ + createErpWorksStages(estid,refId,subCatId); + } + + } + + private void insertErpWorksTask(Integer estid, Integer refId, String estimateNo, Integer subCatId) { + + String sql = """ + INSERT INTO erp_works_task + ( + estid, + ref_id, + estimate_no, + sub_cat_id, + question_id, + ans_id + ) + VALUES (?, ?, ?, ?, NULL, NULL) + """; + + jdbcTemplate.update(sql, estid, refId, estimateNo, subCatId); + } + + private void createErpWorksStages(Integer estid, Integer refId, Integer subCatId) { + + /* SUBCATEGORY 4 */ + + if (subCatId == 4) { + + createStagesForSubCategory4(estid, refId); + + return; + } + + /*OTHER SUBCATEGORIES*/ + + String sql = """ + SELECT + tmid, + typeofwork_id, + code, + taskname, + orderby, + remarks, + percentage + FROM typeofwork_task_master + WHERE typeofwork_id = ? + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + List> rows = jdbcTemplate.queryForList(sql, subCatId); + + /* If matching subcategory rows are not available, use typeofwork_id = 0 */ + + if (rows.isEmpty()) { + + rows = getDefaultTaskMasterRows(); + } + + /* Insert all matching rows into erp_works_stages */ + + insertStages(estid, refId, rows); + } + + private List> getDefaultTaskMasterRows() { + + String sql = """ + SELECT + tmid, + typeofwork_id, + code, + taskname, + orderby, + remarks, + percentage + FROM typeofwork_task_master + WHERE typeofwork_id = 0 + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + return jdbcTemplate.queryForList(sql); + } + + private void createStagesForSubCategory4(Integer estid, Integer refId) { + + /* + Get Question 5 answer + Q5 = Relaying / Forming + */ + + String question5Sql = """ + SELECT am.answer + FROM addworks_details ad + INNER JOIN addworks_answer_master am + ON am.id = ad.answer_id + WHERE ad.estid = ? + AND ad.ref_id = ? + AND ad.question_id = 5 + AND ad.isactive = 1 + AND ad.isdelete = 0 + AND am.isactive = 1 + AND am.isdelete = 0 + LIMIT 1 + """; + + /* + Get Question 4 answer + Q4 = BT / CC + */ + + String question4Sql = """ + SELECT am.answer + FROM addworks_details ad + INNER JOIN addworks_answer_master am + ON am.id = ad.answer_id + WHERE ad.estid = ? + AND ad.ref_id = ? + AND ad.question_id = 4 + AND ad.isactive = 1 + AND ad.isdelete = 0 + AND am.isactive = 1 + AND am.isdelete = 0 + LIMIT 1 + """; + + List> q5Rows = jdbcTemplate.queryForList(question5Sql, estid, refId); + + List> q4Rows = jdbcTemplate.queryForList(question4Sql, estid, refId); + + /* + * If required answers are not available, directly use default stages. + */ + + if (q5Rows.isEmpty() || q4Rows.isEmpty()) { + + insertStages(estid, refId, getDefaultTaskMasterRows()); + + return; + } + + String q5Answer = String.valueOf(q5Rows.get(0).get("answer")).trim(); + + String q4Answer = String.valueOf(q4Rows.get(0).get("answer")).trim(); + + /* + * --------------------------------------------------------- Convert answers to + * code --------------------------------------------------------- + * + * Relaying + BT = 4RBT Relaying + CC = 4RCC Forming + BT = 4FBT Forming + CC = + * 4FCC + */ + + String typeCode = getSubCategory4Code(q5Answer, q4Answer); + + /* + * If answer combination is unexpected, use default stages. + */ + + if (typeCode == null) { + + insertStages(estid, refId, getDefaultTaskMasterRows()); + + return; + } + + /* + * --------------------------------------------------------- Find matching code + * in typeofwork_task_master + * --------------------------------------------------------- + */ + + String stageSql = """ + SELECT + tmid, + typeofwork_id, + code, + taskname, + orderby, + remarks, + percentage + FROM typeofwork_task_master + WHERE typeofwork_id = 4 + AND code = ? + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + List> rows = jdbcTemplate.queryForList(stageSql, typeCode); + + /* + * Code not found -> default stages + */ + + if (rows.isEmpty()) { + + rows = getDefaultTaskMasterRows(); + } + + /* + * Insert ALL matching rows. + */ + + insertStages(estid, refId, rows); + } + + private String getSubCategory4Code( + String q5Answer, + String q4Answer) { + + String prefix = null; + String roadType = null; + + /* + * Q5 + * Relaying -> R + * Forming -> F + */ + + if ("Relaying".equalsIgnoreCase(q5Answer)) { + + prefix = "R"; + + } else if ("Forming".equalsIgnoreCase(q5Answer)) { + + prefix = "F"; + } + + /* + * Q4 + * BT -> BT + * CC -> CC + */ + + if ("BT".equalsIgnoreCase(q4Answer)) { + + roadType = "BT"; + + } else if ("CC".equalsIgnoreCase(q4Answer)) { + + roadType = "CC"; + } + + if (prefix == null || roadType == null) { + + return null; + } + + return "4" + prefix + roadType; + } + + private void insertStages(Integer estid, Integer refId, List> rows) { + + if (rows == null || rows.isEmpty()) { + return; + } + + String sql = """ + INSERT INTO erp_works_stages + ( + estid, + ref_id, + code, + stagename, + orderby, + remarks, + isactive, + isdelete, + percentage + ) + VALUES (?, ?, ?, ?, ?, ?, 1, 0, ?) + """; + + for (Map row : rows) { + + String code = row.get("code") != null ? String.valueOf(row.get("code")) : null; + + String taskName = row.get("taskname") != null ? String.valueOf(row.get("taskname")) : ""; + + Integer orderBy = row.get("orderby") != null ? ((Number) row.get("orderby")).intValue() : 1; + + String remarks = row.get("remarks") != null ? String.valueOf(row.get("remarks")) : ""; + + Integer percentage = row.get("percentage") != null ? ((Number) row.get("percentage")).intValue() : 0; + + jdbcTemplate.update(sql, estid, refId, code, taskName, orderBy, remarks, percentage); + } + } + + public void saveDetails(Map item, Integer createdBy, Integer estid) { + + String sql = """ + INSERT INTO addworks_details + ( + estid, + question_id, + answer_id, + ref_id, + cby + ) + VALUES + (?, ?, ?, ?, ?) + """; + + Integer questionId = Integer.valueOf(String.valueOf(item.get("question_id"))); + + Integer answerId = Integer.valueOf(String.valueOf(item.get("answer_id"))); + + Integer refId = Integer.valueOf(String.valueOf(item.get("ref_id"))); + + jdbcTemplate.update(sql, estid, questionId, answerId, refId, createdBy); + } + + public void saveTextDetails(Map item, Integer createdBy, Integer estid) { + + String sql = """ + INSERT INTO addworks_text_details + ( + estid, + question_id, + answer, + ref_id, + cby + ) + VALUES + (?, ?, ?, ?, ?) + """; + + Integer questionId = Integer.valueOf(String.valueOf(item.get("question_id"))); + + String answer = item.get("answer") != null ? String.valueOf(item.get("answer")) : null; + + Integer refId = Integer.valueOf(String.valueOf(item.get("ref_id"))); + + jdbcTemplate.update(sql, estid, questionId, answer, refId, createdBy); + } + + public List> getSavedWorkDetails(int estid) { + + String sql = """ + SELECT + d.ref_id, + q.id AS question_id, + q.question_name, + q.answer_type, + q.ismandatory, + q.input_source, + q.api_name, + d.answer_id, + a.answer, + q.orderby + FROM addworks_details d + + INNER JOIN addworks_question_master q + ON q.id = d.question_id + + INNER JOIN addworks_answer_master a + ON a.id = d.answer_id + + WHERE d.estid = ? + AND d.isactive = 1 + AND d.isdelete = 0 + AND q.isactive = 1 + AND q.isdelete = 0 + + UNION ALL + + SELECT + t.ref_id, + q.id AS question_id, + q.question_name, + q.answer_type, + q.ismandatory, + q.input_source, + q.api_name, + NULL AS answer_id, + t.answer, + q.orderby + FROM addworks_text_details t + + INNER JOIN addworks_question_master q + ON q.id = t.question_id + + WHERE t.estid = ? + AND t.isactive = 1 + AND t.isdelete = 0 + AND q.isactive = 1 + AND q.isdelete = 0 + + ORDER BY ref_id, orderby + """; + + List> rows = jdbcTemplate.queryForList(sql, estid, estid); + + /* + * Group records by ref_id + */ + Map> grouped = new LinkedHashMap<>(); + + for (Map row : rows) { + + int refId = ((Number) row.get("ref_id")).intValue(); + + Map set = grouped.get(refId); + + if (set == null) { + + set = new LinkedHashMap<>(); + + set.put("ref_id", refId); + + set.put("questions", new ArrayList>()); + + grouped.put(refId, set); + } + + @SuppressWarnings("unchecked") + List> questions = (List>) set.get("questions"); + + Map question = new LinkedHashMap<>(); + + question.put("question_id", row.get("question_id")); + + question.put("question_name", row.get("question_name")); + + question.put("answer_type", row.get("answer_type")); + + question.put("ismandatory", row.get("ismandatory")); + + question.put("input_source", row.get("input_source")); + + question.put("api_name", row.get("api_name")); + + question.put("answer_id", row.get("answer_id")); + + question.put("answer", row.get("answer")); + + questions.add(question); + } + + return new ArrayList<>(grouped.values()); + } + + public String checkDuplicateRoad(Integer estid, List> textDetails) { + + if (textDetails == null || textDetails.isEmpty()) { + return null; + } + + /* + * Get ROAD question IDs + */ + String roadQuestionSql = """ + SELECT id + FROM addworks_question_master + WHERE subcategory_id = 4 + AND input_source = 'API' + AND api_name = 'ROAD' + AND isactive = 1 + AND isdelete = 0 + """; + + List> roadQuestions = jdbcTemplate.queryForList(roadQuestionSql); + + if (roadQuestions.isEmpty()) { + return null; + } + + Set roadQuestionIds = new HashSet<>(); + + for (Map row : roadQuestions) { + + roadQuestionIds.add(((Number) row.get("id")).intValue()); + } + + /* + * Get existing ROAD answers + */ + String existingSql = """ + SELECT answer + FROM addworks_text_details + WHERE estid = ? + AND question_id IN ( + SELECT id + FROM addworks_question_master + WHERE subcategory_id = 4 + AND input_source = 'API' + AND api_name = 'ROAD' + AND isactive = 1 + AND isdelete = 0 + ) + AND isactive = 1 + AND isdelete = 0 + """; + + List> existingRows = jdbcTemplate.queryForList(existingSql, estid); + + /* + * Check new records against existing records + */ + for (Map item : textDetails) { + + Integer questionId = Integer.valueOf(String.valueOf(item.get("question_id"))); + + if (!roadQuestionIds.contains(questionId)) { + continue; + } + + String answer = item.get("answer") != null ? String.valueOf(item.get("answer")) : ""; + + if (answer.trim().isEmpty()) { + continue; + } + + String[] parts = answer.split(",", -1); + + String roadId = parts[0].trim(); + + String roadName = parts.length > 1 ? parts[1].trim() : roadId; + + /* + * Compare with existing DB records + */ + for (Map existing : existingRows) { + + String existingAnswer = existing.get("answer") != null ? String.valueOf(existing.get("answer")) : ""; + + if (existingAnswer.trim().isEmpty()) { + continue; + } + + String[] existingParts = existingAnswer.split(",", -1); + + String existingRoadId = existingParts[0].trim(); + + if (roadId.equals(existingRoadId)) { + + return roadName; + } + } + } + + return null; + } + + @Transactional + public Map deleteSavedWorkDetails(int createdBy, int estid, int refId) { + + Map response = new HashMap<>(); + + /* + * First check work progress + */ + if (isWorkProgressStarted(estid, refId)) { + + response.put("status", false); + response.put("message", "Work progress is started, Unable to edit or remove"); + + return response; + } + + /* + * 1. Deactivate addworks_details + */ + String detailsSql = """ + UPDATE addworks_details + SET + updated_by = ?, + updated_date = NOW(), + isactive = 0, + isdelete = 1 + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + int detailsUpdated = jdbcTemplate.update(detailsSql, createdBy, estid, refId); + + /* + * 2. Deactivate addworks_text_details + */ + String textDetailsSql = """ + UPDATE addworks_text_details + SET + updated_by = ?, + updated_date = NOW(), + isactive = 0, + isdelete = 1 + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + int textDetailsUpdated = jdbcTemplate.update(textDetailsSql, createdBy, estid, refId); + + /* + * 3. Deactivate erp_works_task + */ + String taskSql = """ + UPDATE erp_works_task + SET + isactive = 0, + isdelete = 1 + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + int taskUpdated = jdbcTemplate.update(taskSql, estid, refId); + + /* + * 4. Deactivate erp_works_stages + */ + String stagesSql = """ + UPDATE erp_works_stages + SET + isactive = 0, + isdelete = 1 + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + int stagesUpdated = jdbcTemplate.update(stagesSql, estid, refId); + + boolean deleted = detailsUpdated > 0 || textDetailsUpdated > 0 || taskUpdated > 0 || stagesUpdated > 0; + + response.put("status", deleted); + + response.put("message", deleted ? "Work details removed successfully" : "Work details not found"); + + return response; + } + + public List> getEditWorkDetails(int estid, int refId, int subcategoryId) { + + /* Get questions for the subcategory */ + + String questionSql = """ + SELECT + id, + subcategory_id, + issub, + question_name, + answer_type, + ismandatory, + allow_zero, + orderby, + remarks, + input_source, + api_name + FROM addworks_question_master + WHERE subcategory_id = ? + AND issub = 0 + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + List> questions = jdbcTemplate.queryForList(questionSql, subcategoryId); + + String savedSql = """ + SELECT + question_id, + answer_id, + answer, + source_type + FROM + ( + SELECT + question_id, + answer_id, + NULL AS answer, + 'MASTER' AS source_type + FROM addworks_details + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + + UNION ALL + + SELECT + question_id, + NULL AS answer_id, + answer, + 'TEXT' AS source_type + FROM addworks_text_details + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + ) x + """; + + List> savedRows = jdbcTemplate.queryForList(savedSql, estid, refId, estid, refId); + + + Map> savedMap = new HashMap<>(); + + for (Map row : savedRows) { + + Integer questionId = ((Number) row.get("question_id")).intValue(); + + savedMap.put(questionId, row); + } + + + String answerSql = """ + SELECT + id, + question_id, + answer, + orderby, + remarks + FROM addworks_answer_master + WHERE question_id = ? + AND isactive = 1 + AND isdelete = 0 + ORDER BY orderby + """; + + for (Map question : questions) { + + int questionId = ((Number) question.get("id")).intValue(); + + String inputSource = String.valueOf(question.get("input_source")); + + String answerType = String.valueOf(question.get("answer_type")); + + /* + * MASTER dropdown / radio + */ + if ("MASTER".equalsIgnoreCase(inputSource) + && ("radio".equalsIgnoreCase(answerType) || "dropdown".equalsIgnoreCase(answerType))) { + + question.put("answers", jdbcTemplate.queryForList(answerSql, questionId)); + + } else { + + question.put("answers", new ArrayList>()); + } + + /* + * Get saved answer + */ + Map saved = savedMap.get(questionId); + + if (saved != null) { + + question.put("saved_answer_id", saved.get("answer_id")); + + question.put("saved_answer", saved.get("answer")); + + } else { + + question.put("saved_answer_id", null); + + question.put("saved_answer", null); + } + } + + return questions; + } + + public String checkDuplicateRoadForUpdate(int estid, int refId, List> textDetails) { + + if (textDetails == null || textDetails.isEmpty()) { + return null; + } + + Set requestRoadIds = new HashSet<>(); + + for (Map row : textDetails) { + + Integer questionId = Integer.valueOf(String.valueOf(row.get("question_id"))); + + String answer = row.get("answer") == null ? null : String.valueOf(row.get("answer")); + + if (answer == null || answer.trim().isEmpty()) { + continue; + } + + String apiName = jdbcTemplate.queryForObject(""" + SELECT api_name + FROM addworks_question_master + WHERE id = ? + """, String.class, questionId); + + if (!"ROAD".equalsIgnoreCase(apiName)) { + continue; + } + + String[] parts = answer.split(",", -1); + + String roadId = parts[0].trim(); + + String roadName = parts.length > 1 ? parts[1].trim() : roadId; + + /* + * Duplicate inside same update request + */ + if (!requestRoadIds.add(roadId)) { + return roadName; + } + + /* + * Check other ref_ids + */ + String existingSql = """ + SELECT COUNT(*) + FROM addworks_text_details td + JOIN addworks_question_master qm + ON qm.id = td.question_id + WHERE td.estid = ? + AND td.ref_id <> ? + AND td.isactive = 1 + AND td.isdelete = 0 + AND qm.input_source = 'API' + AND qm.api_name = 'ROAD' + AND SUBSTRING_INDEX(td.answer, ',', 1) = ? + """; + + Integer count = jdbcTemplate.queryForObject(existingSql, Integer.class, estid, refId, roadId); + + if (count != null && count > 0) { + return roadName; + } + } + + return null; + } + + @Transactional + public Map updateSavedWorkDetails( + int updatedBy, + int estid, + int refId, + String estimateNo, + int subCatId, + List> details, + List> textDetails) { + + Map response = new HashMap<>(); + + if (isWorkProgressStarted(estid, refId)) { + + response.put("status", false); + response.put("message", "Work progress is started, Unable to edit or remove"); + + return response; + } + + /* + STEP 1 + Log current Add Works details + */ + + logAddWorksDetails(updatedBy, estid, refId); + + + /* + STEP 2 + Log current Add Works text details + */ + + logAddWorksTextDetails(updatedBy, estid, refId); + + + /* + STEP 3 + Log current ERP task + */ + + logErpWorksTask(updatedBy, estid, refId); + + + /* + STEP 4 + Log current ERP stages + */ + + logErpWorksStages(updatedBy, estid, refId); + + + /* + STEP 5 + Update Add Works MASTER details + */ + + updateAddWorksDetails(updatedBy, estid, refId, details); + + + /* + STEP 6 + Update Add Works TEXT/API details + */ + + updateAddWorksTextDetails(updatedBy, estid, refId, textDetails); + + + /* + STEP 7 + Update ERP task + Only one task record for this estid + ref_id. + question_id and ans_id remain NULL. + + */ + + updateErpWorksTask(estid, refId, estimateNo, subCatId); + + + /* + STEP 8 + Deactivate old stages + */ + + deactivateOldStages(estid, refId); + + + /* + STEP 9 + Create stages again based on updated answers + */ + + createErpWorksStages(estid, refId, subCatId); + + response.put("status", true); + response.put("message", "Work details updated successfully"); + + return response; + } + + private void logAddWorksDetails(int loggedBy, int estid, int refId) { + + String sql = """ + INSERT INTO addworks_details_log + ( + adid, + estid, + question_id, + answer_id, + ref_id, + cby, + updated_by, + updated_date, + isactive, + isdelete, + cdate, + logged_by, + logged_date + ) + SELECT + id, + estid, + question_id, + answer_id, + ref_id, + cby, + updated_by, + updated_date, + isactive, + isdelete, + cdate, + ?, + NOW() + FROM addworks_details + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + jdbcTemplate.update(sql, loggedBy, estid, refId); + } + + private void logAddWorksTextDetails(int loggedBy, int estid, int refId) { + + String sql = """ + INSERT INTO addworks_text_details_log + ( + atdid, + estid, + question_id, + answer, + ref_id, + cby, + updated_by, + updated_date, + isactive, + isdelete, + cdate, + logged_by, + logged_date + ) + SELECT + id, + estid, + question_id, + answer, + ref_id, + cby, + updated_by, + updated_date, + isactive, + isdelete, + cdate, + ?, + NOW() + FROM addworks_text_details + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + jdbcTemplate.update(sql, loggedBy, estid, refId); + } + + private void logErpWorksTask(int loggedBy, int estid, int refId) { + + String sql = """ + INSERT INTO erp_works_task_log + ( + task_id, + estid, + ref_id, + estimate_no, + sub_cat_id, + question_id, + ans_id, + remarks, + cdate, + isactive, + isdelete, + percentage, + logged_by, + logged_date + ) + SELECT + id, + estid, + ref_id, + estimate_no, + sub_cat_id, + question_id, + ans_id, + remarks, + cdate, + isactive, + isdelete, + percentage, + ?, + NOW() + FROM erp_works_task + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + jdbcTemplate.update(sql, loggedBy, estid, refId); + } + + private void logErpWorksStages(int loggedBy, int estid, int refId) { + + String sql = """ + INSERT INTO erp_works_stages_log + ( + stage_id, + estid, + ref_id, + code, + stagename, + orderby, + remarks, + isactive, + isdelete, + percentage, + logged_by, + logged_date + ) + SELECT + tmid, + estid, + ref_id, + code, + stagename, + orderby, + remarks, + isactive, + isdelete, + percentage, + ?, + NOW() + FROM erp_works_stages + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + jdbcTemplate.update(sql, loggedBy, estid, refId); + } + + private void updateAddWorksDetails(int updatedBy, int estid, int refId, List> details) { + + if (details == null || details.isEmpty()) { + return; + } + + String findSql = """ + SELECT id + FROM addworks_details + WHERE estid = ? + AND question_id = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + LIMIT 1 + """; + + String updateSql = """ + UPDATE addworks_details + SET + answer_id = ?, + updated_by = ?, + updated_date = NOW() + WHERE id = ? + AND estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + for (Map row : details) { + + Integer questionId = Integer.valueOf(String.valueOf(row.get("question_id"))); + + Integer answerId = Integer.valueOf(String.valueOf(row.get("answer_id"))); + + List> existingRows = jdbcTemplate.queryForList(findSql, estid, questionId, refId); + + if (!existingRows.isEmpty()) { + + Integer id = ((Number) existingRows.get(0).get("id")).intValue(); + + jdbcTemplate.update(updateSql, answerId, updatedBy, id, estid, refId); + } + } + } + + private void updateAddWorksTextDetails(int updatedBy, int estid, int refId, List> textDetails) { + + if (textDetails == null || textDetails.isEmpty()) { + return; + } + + String findSql = """ + SELECT id + FROM addworks_text_details + WHERE estid = ? + AND question_id = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + LIMIT 1 + """; + + String updateSql = """ + UPDATE addworks_text_details + SET + answer = ?, + updated_by = ?, + updated_date = NOW() + WHERE id = ? + AND estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + for (Map row : textDetails) { + + Integer questionId = Integer.valueOf(String.valueOf(row.get("question_id"))); + + String answer = row.get("answer") == null ? null : String.valueOf(row.get("answer")); + + List> existingRows = jdbcTemplate.queryForList(findSql, estid, questionId, refId); + + if (!existingRows.isEmpty()) { + + Integer id = ((Number) existingRows.get(0).get("id")).intValue(); + + jdbcTemplate.update(updateSql, answer, updatedBy, id, estid, refId); + } + } + } + + private void updateErpWorksTask(int estid, int refId, String estimateNo, int subCatId) { + + String sql = """ + UPDATE erp_works_task + SET + estimate_no = ?, + sub_cat_id = ?, + question_id = NULL, + ans_id = NULL + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + int updated = jdbcTemplate.update(sql, estimateNo, subCatId, estid, refId); + + /* + * Normally the task must already exist because this is an update operation. + */ + if (updated == 0) { + + String insertSql = """ + INSERT INTO erp_works_task + ( + estid, + ref_id, + estimate_no, + sub_cat_id, + question_id, + ans_id + ) + VALUES (?, ?, ?, ?, NULL, NULL) + """; + + jdbcTemplate.update(insertSql, estid, refId, estimateNo, subCatId); + } + } + + private void deactivateOldStages(int estid, int refId) { + + String sql = """ + UPDATE erp_works_stages + SET + isactive = 0, + isdelete = 1 + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + AND isdelete = 0 + """; + + jdbcTemplate.update(sql, estid, refId); + } + + public boolean isWorkProgressStarted(int estid, int refId) { + + String sql = """ + SELECT COUNT(*) + FROM erp_task_data + WHERE estid = ? + AND ref_id = ? + AND isactive = 1 + """; + + Integer count = jdbcTemplate.queryForObject(sql, Integer.class, estid, refId); + + return count != null && count > 0; + } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 5c2b240..2f562e6 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -1,5 +1,5 @@ -spring.profiles.active=local -#spring.profiles.active=production +#spring.profiles.active=local +spring.profiles.active=production #For Server production #assets.base-url=/gcc/assets/ #For local test diff --git a/src/main/resources/templates/fragments/modules/works/edit_stage_script.html b/src/main/resources/templates/fragments/modules/works/edit_stage_script.html index 98a867e..c528194 100644 --- a/src/main/resources/templates/fragments/modules/works/edit_stage_script.html +++ b/src/main/resources/templates/fragments/modules/works/edit_stage_script.html @@ -56,7 +56,7 @@ function get_works_stage_data_data(){ function get_works_stage_details() { var formData = new FormData(); - var apiUrl = '/gcc/works/api/estimates/getUserEstWorkDetailsById?estid='+estid; + var apiUrl = '/gcc/api/works/estimates/getUserEstWorkDetailsById?estid='+estid; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ diff --git a/src/main/resources/templates/fragments/modules/works/script.html b/src/main/resources/templates/fragments/modules/works/script.html index d644483..b3ea419 100644 --- a/src/main/resources/templates/fragments/modules/works/script.html +++ b/src/main/resources/templates/fragments/modules/works/script.html @@ -26,7 +26,7 @@ } function loadScheme() { - fetch('/gcc/works/api/estimates/getSchemeList') + fetch('/gcc/api/works/estimates/getSchemeList') .then(response => response.json()) .then(data => { let schemeDropdown = document.getElementById('erpscheme'); @@ -43,7 +43,7 @@ } function loadCategory() { - fetch('/gcc/works/api/estimates/getCategoryList') + fetch('/gcc/api/works/estimates/getCategoryList') .then(response => response.json()) .then(data => { let categoryDropdown = document.getElementById('erpcategory'); @@ -60,7 +60,7 @@ } function loadSubCategory() { - fetch('/gcc/works/api/estimates/getSubCategoryList') + fetch('/gcc/api/works/estimates/getSubCategoryList') .then(response => response.json()) .then(data => { let subCategoryDropdown = document.getElementById('erpsubcategory'); @@ -77,7 +77,7 @@ } function loadDepartment() { - fetch('/gcc/works/api/estimates/getDepartmentList') + fetch('/gcc/api/works/estimates/getDepartmentList') .then(response => response.json()) .then(data => { let departmentDropdown = document.getElementById('erpdepartment'); @@ -94,7 +94,7 @@ } function loadSource() { - fetch('/gcc/works/api/estimates/getSourceofFundList') + fetch('/gcc/api/works/estimates/getSourceofFundList') .then(response => response.json()) .then(data => { let SourceDropDown = document.getElementById('erpfundsource'); @@ -131,7 +131,7 @@ } function loadDepartmentFilter() { - fetch('/gcc/works/api/estimates/getDepartmentList') + fetch('/gcc/api/works/estimates/getDepartmentList') .then(response => response.json()) .then(data => { let departmentDropdown = document.getElementById('departmentf'); @@ -148,7 +148,7 @@ } function loadSourceFilter() { - fetch('/gcc/works/api/estimates/getSourceofFundList') + fetch('/gcc/api/works/estimates/getSourceofFundList') .then(response => response.json()) .then(data => { let SourceDropDown = document.getElementById('fundsourcef'); diff --git a/src/main/resources/templates/fragments/modules/works/user_works_update_script.html b/src/main/resources/templates/fragments/modules/works/user_works_update_script.html index d610397..de388c1 100644 --- a/src/main/resources/templates/fragments/modules/works/user_works_update_script.html +++ b/src/main/resources/templates/fragments/modules/works/user_works_update_script.html @@ -179,7 +179,7 @@ function get_works_update_details() { var formData = new FormData(); - var apiUrl = '/gcc/works/api/estimates/getUserEstWorkDetailsById?estid='+estid; + var apiUrl = '/gcc/api/works/estimates/getUserEstWorkDetailsById?estid='+estid; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ @@ -193,13 +193,11 @@ resolve(jsonResponse); }else{ //call_petition_search_from("Invalid Petition Number: Please provide a valid petition number."); - console.log('Fetched petition details ('+petitionNo+') Is null:'); } }, error: function(xhr, status, error) { // Reject the Promise with the error message - console.error('Error fetching petition details ('+petitionNo+'):', error.message); reject(error); } }); diff --git a/src/main/resources/templates/fragments/modules/works/user_works_view_script.html b/src/main/resources/templates/fragments/modules/works/user_works_view_script.html index c37c4b3..51c5b37 100644 --- a/src/main/resources/templates/fragments/modules/works/user_works_view_script.html +++ b/src/main/resources/templates/fragments/modules/works/user_works_view_script.html @@ -174,7 +174,7 @@ function get_works_details() { var formData = new FormData(); - var apiUrl = '/gcc/works/api/estimates/getUserEstWorkDetailsById?estid='+estid; + var apiUrl = '/gcc/api/works/estimates/getUserEstWorkDetailsById?estid='+estid; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ @@ -253,7 +253,7 @@ } function getStageList(estid){ var formData = new FormData(); - var apiUrl = '/gcc/works/api/estimates/getUserEstWorkStageDetailsByEstid?estid='+estid; + var apiUrl = '/gcc/api/works/estimates/getUserEstWorkStageDetailsByEstid?estid='+estid; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ diff --git a/src/main/resources/templates/fragments/modules/works/works_view_script.html b/src/main/resources/templates/fragments/modules/works/works_view_script.html index bb2402e..b4381f6 100644 --- a/src/main/resources/templates/fragments/modules/works/works_view_script.html +++ b/src/main/resources/templates/fragments/modules/works/works_view_script.html @@ -62,7 +62,7 @@ function get_works_details() { var formData = new FormData(); - var apiUrl = '/gcc/works/api/estimates/getestimateworkdetailsById?estid='+estid; + var apiUrl = '/gcc/api/works/estimates/getestimateworkdetailsById?estid='+estid; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ diff --git a/src/main/resources/templates/modules/works/addworkspage.html b/src/main/resources/templates/modules/works/addworkspage.html new file mode 100644 index 0000000..b0e0885 --- /dev/null +++ b/src/main/resources/templates/modules/works/addworkspage.html @@ -0,0 +1,3931 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Works Module - Estimates + + + + + + + + + + + + + Estimates Information: + + + + + + + + + + + + Estimates No: + + + Estimate Date: + + + + + Zone: + + + Ward: + + + + + Project Name: + + + + + Location: + + + + + Department: + + + Estimate Amount: + + + + + Source of Fund: + + + Scheme: + + + + + Category: + + + Sub-Category: + + + + + + + + + + + + + + + + + + + Work Details + + 0 + + + + + + + + + + + + + + Add Work Details + + Add More + + + + + + + + + + + Save Works Details + + + + Back + + + + + + + + + + + + + + + + + + Loading... + + + Please wait... + + + + + + + + + + Edit + + + + × + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/templates/modules/works/erp-works-list.html b/src/main/resources/templates/modules/works/erp-works-list.html index f0a1495..51cb449 100644 --- a/src/main/resources/templates/modules/works/erp-works-list.html +++ b/src/main/resources/templates/modules/works/erp-works-list.html @@ -318,7 +318,7 @@ //alert("finYear:"+finYear); //alert("oValue:"+oValue); - var apiUrl = '/gcc/works/api/estimates/getFilteredERpWorksList?loginId='+createdBy+'&finYear='+finYear+'&oValue='+oValue; + var apiUrl = '/gcc/api/works/estimates/getFilteredERpWorksList?loginId='+createdBy+'&finYear='+finYear+'&oValue='+oValue; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ @@ -714,7 +714,7 @@ formData.set("isiconic", iconicProjectValue); $.ajax({ - url: "/gcc/works/api/estimates/saveEstimateWorkDetails", + url: "/gcc/api/works/estimates/saveEstimateWorkDetails", type: "POST", contentType: false, processData: false, diff --git a/src/main/resources/templates/modules/works/erp-works-update.html b/src/main/resources/templates/modules/works/erp-works-update.html index 7979671..174524a 100644 --- a/src/main/resources/templates/modules/works/erp-works-update.html +++ b/src/main/resources/templates/modules/works/erp-works-update.html @@ -550,7 +550,7 @@ // AJAX call $.ajax({ - url: "/gcc/works/api/estimates/getERPWorksDetails", + url: "/gcc/api/works/estimates/getERPWorksDetails", type: "GET", data: requestData, dataType: "json", @@ -724,7 +724,7 @@ document.addEventListener("DOMContentLoaded", function () { } function loadScheme() { - fetch('/gcc/works/api/estimates/getSchemeList') + fetch('/gcc/api/works/estimates/getSchemeList') .then(response => response.json()) .then(data => { let schemeDropdown = document.getElementById('scheme'); @@ -741,7 +741,7 @@ document.addEventListener("DOMContentLoaded", function () { } function loadCategory() { - fetch('/gcc/works/api/estimates/getCategoryList') + fetch('/gcc/api/works/estimates/getCategoryList') .then(response => response.json()) .then(data => { let categoryDropdown = document.getElementById('category'); @@ -758,7 +758,7 @@ document.addEventListener("DOMContentLoaded", function () { } function loadSubCategory() { - fetch('/gcc/works/api/estimates/getSubCategoryList') + fetch('/gcc/api/works/estimates/getSubCategoryList') .then(response => response.json()) .then(data => { let subCategoryDropdown = document.getElementById('subcategory'); @@ -775,7 +775,7 @@ document.addEventListener("DOMContentLoaded", function () { } function loadDepartment() { - fetch('/gcc/works/api/estimates/getDepartmentList') + fetch('/gcc/api/works/estimates/getDepartmentList') .then(response => response.json()) .then(data => { let departmentDropdown = document.getElementById('department'); @@ -792,7 +792,7 @@ document.addEventListener("DOMContentLoaded", function () { } function loadSource() { - fetch('/gcc/works/api/estimates/getSourceofFundList') + fetch('/gcc/api/works/estimates/getSourceofFundList') .then(response => response.json()) .then(data => { let SourceDropDown = document.getElementById('fundsource'); @@ -809,7 +809,7 @@ document.addEventListener("DOMContentLoaded", function () { } function loadEstCode() { - fetch('/gcc/works/api/estimates/getEstimateCode') + fetch('/gcc/api/works/estimates/getEstimateCode') .then(response => response.json()) .then(data => { let estCodeDropdown = document.getElementById('estcode'); @@ -877,7 +877,7 @@ document.addEventListener("DOMContentLoaded", function () { } $.ajax({ - url: "/gcc/works/api/estimates/save", + url: "/gcc/api/works/estimates/save", type: "POST", data: formData, processData: false, diff --git a/src/main/resources/templates/modules/works/erpworkslist.html b/src/main/resources/templates/modules/works/erpworkslist.html index 59b2ceb..589d903 100644 --- a/src/main/resources/templates/modules/works/erpworkslist.html +++ b/src/main/resources/templates/modules/works/erpworkslist.html @@ -131,6 +131,7 @@ Estimation Amount Order Value + Add Works @@ -316,7 +317,7 @@ var oValue = document.getElementById('oValue').value; //alert(finYear); //alert(oValue); - var apiUrl = '/gcc/works/api/estimates/getFilteredERpWorksListByLogin?loginId='+createdBy+'&finYear='+finYear+'&oValue='+oValue; + var apiUrl = '/gcc/api/works/estimates/getFilteredERpWorksListByLogin?loginId='+createdBy+'&finYear='+finYear+'&oValue='+oValue; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ @@ -384,6 +385,16 @@ Update Work tasks--> `; + + AddWorksButtonHTML = ` + + + Add works + + + `; table.row.add([ rowNum++, @@ -396,7 +407,8 @@ row['sub_category'], row['project_name'], row['estimation_amount'], - row['est_val_with_oh'] + row['est_val_with_oh'], + AddWorksButtonHTML ]); }); @@ -408,6 +420,15 @@ remove_loading(); // remove Loading } + function gotopage(estid, subCategoryId,estimate_no,sub_category) { + var url = "/gcc/works/addworks" + + "?estid=" + encodeURIComponent(estid) + + "&sub_category_id=" + encodeURIComponent(subCategoryId) + + "&estimate_no=" + encodeURIComponent(estimate_no) + + "&sub_category=" + encodeURIComponent(sub_category); + + window.open(url, "_blank"); + } function viewUserWorksSummary(estid){ $("#viewWorks").modal({ @@ -726,7 +747,7 @@ formData.set("isiconic", iconicProjectValue); $.ajax({ - url: "/gcc/works/api/estimates/updateEstimateWorkDetails", + url: "/gcc/api/works/estimates/updateEstimateWorkDetails", type: "POST", contentType: false, processData: false, diff --git a/src/main/resources/templates/modules/works/erpworkslist_old.html b/src/main/resources/templates/modules/works/erpworkslist_old.html index 22593b6..93b80cc 100644 --- a/src/main/resources/templates/modules/works/erpworkslist_old.html +++ b/src/main/resources/templates/modules/works/erpworkslist_old.html @@ -1356,7 +1356,7 @@ }); } else { $.ajax({ - url: "/gcc/works/api/estimates/getFilteredWorks", + url: "/gcc/api/works/estimates/getFilteredWorks", type: "GET", data: { zone: zone, @@ -1463,7 +1463,7 @@ $('#worksDatatable').on('click', 'td:nth-child(2)', function () { var estimateNo = $(this).text().trim(); $.ajax({ - url: '/gcc/works/api/estimates/fetchERPdetails', + url: '/gcc/api/works/estimates/fetchERPdetails', method: 'GET', data: {estimateNo: estimateNo}, success: function (response) { @@ -1786,7 +1786,7 @@ } $.ajax({ - url: "/gcc/works/api/estimates/updateERPEstimate", + url: "/gcc/api/works/estimates/updateERPEstimate", type: "POST", contentType: false, processData: false, @@ -1940,7 +1940,7 @@ } function loadScheme() { - fetch('/gcc/works/api/estimates/getSchemeList') + fetch('/gcc/api/works/estimates/getSchemeList') .then(response => response.json()) .then(data => { let schemeDropdown = document.getElementById('erpscheme'); @@ -1957,7 +1957,7 @@ } function loadCategory() { - fetch('/gcc/works/api/estimates/getCategoryList') + fetch('/gcc/api/works/estimates/getCategoryList') .then(response => response.json()) .then(data => { let categoryDropdown = document.getElementById('erpcategory'); @@ -1974,7 +1974,7 @@ } function loadSubCategory() { - fetch('/gcc/works/api/estimates/getSubCategoryList') + fetch('/gcc/api/works/estimates/getSubCategoryList') .then(response => response.json()) .then(data => { let subCategoryDropdown = document.getElementById('erpsubcategory'); @@ -1991,7 +1991,7 @@ } function loadDepartment() { - fetch('/gcc/works/api/estimates/getDepartmentList') + fetch('/gcc/api/works/estimates/getDepartmentList') .then(response => response.json()) .then(data => { let departmentDropdown = document.getElementById('erpdepartment'); @@ -2008,7 +2008,7 @@ } function loadSource() { - fetch('/gcc/works/api/estimates/getSourceofFundList') + fetch('/gcc/api/works/estimates/getSourceofFundList') .then(response => response.json()) .then(data => { let SourceDropDown = document.getElementById('erpfundsource'); @@ -2045,7 +2045,7 @@ } function loadDepartmentFilter() { - fetch('/gcc/works/api/estimates/getDepartmentList') + fetch('/gcc/api/works/estimates/getDepartmentList') .then(response => response.json()) .then(data => { let departmentDropdown = document.getElementById('departmentf'); @@ -2062,7 +2062,7 @@ } function loadSourceFilter() { - fetch('/gcc/works/api/estimates/getSourceofFundList') + fetch('/gcc/api/works/estimates/getSourceofFundList') .then(response => response.json()) .then(data => { let SourceDropDown = document.getElementById('fundsourcef'); @@ -2125,7 +2125,7 @@ function fetchEstimateInformation(estimateCode) { $.ajax({ - url: '/gcc/works/api/estimates/getestimatedetails', // API to fetch employee details + url: '/gcc/api/works/estimates/getestimatedetails', // API to fetch employee details type: 'GET', data: {estimateCode: estimateCode}, // Pass EMPLOYEE_CODE as a parameter success: function (response) { @@ -2255,7 +2255,7 @@ function fetchEstimateDetails(estimateCode) { $.ajax({ - url: '/gcc/works/api/estimates/getestimatedetails', // API to fetch employee details + url: '/gcc/api/works/estimates/getestimatedetails', // API to fetch employee details type: 'GET', data: {estimateCode: estimateCode}, // Pass EMPLOYEE_CODE as a parameter success: function (response) { @@ -2308,7 +2308,7 @@ $(document).ready(function () { $.ajax({ - url: "/gcc/works/api/estimates/reasonlist", + url: "/gcc/api/works/estimates/reasonlist", type: "GET", dataType: "json", success: function (response) { @@ -2422,7 +2422,7 @@ console.log("subCategoryId", subCategoryId) $.ajax({ - url: "/gcc/works/api/estimates/questions", // Your API endpoint + url: "/gcc/api/works/estimates/questions", // Your API endpoint type: "GET", data: {subCatId: subCategoryId}, // Passing sub_cat_id dynamically dataType: "json", @@ -2684,7 +2684,7 @@ function fetchRelatedQuestions(answerId, parentDiv) { $.ajax({ - url: `/gcc/works/api/estimates/answerIdd?answerId=${answerId}`, // Your API URL + url: `/gcc/api/works/estimates/answerIdd?answerId=${answerId}`, // Your API URL type: "GET", dataType: "json", success: function (response) { @@ -2818,7 +2818,7 @@ } $.ajax({ - url: "/gcc/works/api/estimates/saveErplist", + url: "/gcc/api/works/estimates/saveErplist", type: "POST", contentType: "application/json", data: JSON.stringify(selectedData), @@ -2861,7 +2861,7 @@ // Fetch Saved Data for the Estimate Number $.ajax({ - url: `/gcc/works/api/estimates/fetchErpData?estimateNumber=${encodeURIComponent(estimateNo)}`, + url: `/gcc/api/works/estimates/fetchErpData?estimateNumber=${encodeURIComponent(estimateNo)}`, type: "GET", success: function (response) { console.log("response>>>>>>>>>>>>>>", response) diff --git a/src/main/resources/templates/modules/works/erpworkslist_report.html b/src/main/resources/templates/modules/works/erpworkslist_report.html index 8c36099..6765a96 100644 --- a/src/main/resources/templates/modules/works/erpworkslist_report.html +++ b/src/main/resources/templates/modules/works/erpworkslist_report.html @@ -350,7 +350,7 @@ /* Get Erp works Data */ async function get_erp_work_data() { - var apiUrl = '/gcc/works/api/estimates/getFilteredERpWorksListByLogin?loginId='+createdBy; + var apiUrl = '/gcc/api/works/estimates/getFilteredERpWorksListByLogin?loginId='+createdBy; // Return a Promise return new Promise(function(resolve, reject) { $.ajax({ @@ -741,7 +741,7 @@ formData.set("isiconic", iconicProjectValue); $.ajax({ - url: "/gcc/works/api/estimates/updateEstimateWorkDetails", + url: "/gcc/api/works/estimates/updateEstimateWorkDetails", type: "POST", contentType: false, processData: false, diff --git a/src/main/resources/templates/modules/works/non-erp-works-add.html b/src/main/resources/templates/modules/works/non-erp-works-add.html index 67dddeb..35390b3 100644 --- a/src/main/resources/templates/modules/works/non-erp-works-add.html +++ b/src/main/resources/templates/modules/works/non-erp-works-add.html @@ -585,7 +585,7 @@ } function loadScheme() { - fetch('/gcc/works/api/estimates/getSchemeList') + fetch('/gcc/api/works/estimates/getSchemeList') .then(response => response.json()) .then(data => { let schemeDropdown = document.getElementById('scheme'); @@ -602,7 +602,7 @@ } function loadCategory() { - fetch('/gcc/works/api/estimates/getCategoryList') + fetch('/gcc/api/works/estimates/getCategoryList') .then(response => response.json()) .then(data => { let categoryDropdown = document.getElementById('category'); @@ -619,7 +619,7 @@ } function loadSubCategory() { - fetch('/gcc/works/api/estimates/getSubCategoryList') + fetch('/gcc/api/works/estimates/getSubCategoryList') .then(response => response.json()) .then(data => { let subCategoryDropdown = document.getElementById('subcategory'); @@ -636,7 +636,7 @@ } function loadDepartment() { - fetch('/gcc/works/api/estimates/getDepartmentList') + fetch('/gcc/api/works/estimates/getDepartmentList') .then(response => response.json()) .then(data => { let departmentDropdown = document.getElementById('department'); @@ -653,7 +653,7 @@ } function loadSource() { - fetch('/gcc/works/api/estimates/getSourceofFundList') + fetch('/gcc/api/works/estimates/getSourceofFundList') .then(response => response.json()) .then(data => { let SourceDropDown = document.getElementById('fundsource'); @@ -851,7 +851,7 @@ // Submit the form data using AJAX $.ajax({ - url: "/gcc/works/api/estimates/nonerpForm", + url: "/gcc/api/works/estimates/nonerpForm", type: "POST", data: formData, processData: false, @@ -894,7 +894,7 @@ $(document).ready(function () { $.ajax({ - url: "/gcc/works/api/estimates/reasonlist", + url: "/gcc/api/works/estimates/reasonlist", type: "GET", dataType: "json", success: function (response) { diff --git a/src/main/resources/templates/modules/works/nonerpworkslist.html b/src/main/resources/templates/modules/works/nonerpworkslist.html index d2e4124..8f8c303 100644 --- a/src/main/resources/templates/modules/works/nonerpworkslist.html +++ b/src/main/resources/templates/modules/works/nonerpworkslist.html @@ -213,12 +213,24 @@ + + + Add Works + + + +
Please wait...