From 59b572d6912c1cd23c0ad244b280abb54ab0b56a Mon Sep 17 00:00:00 2001 From: "usama.jameel" Date: Thu, 26 Jun 2025 12:20:56 +0500 Subject: [PATCH 1/2] add pagination in cutting report and count in reporting sidebars --- .../controller/POStatusController.java | 5 +- .../controller/ReportingController.java | 11 ++-- .../dao/ctp/InventoryTransactionLegDAO.java | 4 -- .../dao/ctp/PurchaseOrderCTPDao.java | 13 +++-- .../SummaryInventoryReportQueryBuilder.java | 3 +- .../service/ReportingService.java | 20 ++++---- .../reporting/cutting-report-sidebar.html | 4 ++ .../templates/reporting/cutting-report.html | 50 +++++++++++++++++-- .../reporting/po-report-sidebar.html | 4 ++ 9 files changed, 81 insertions(+), 33 deletions(-) diff --git a/src/main/java/com/utopiaindustries/controller/POStatusController.java b/src/main/java/com/utopiaindustries/controller/POStatusController.java index b4318aa..b9e353b 100644 --- a/src/main/java/com/utopiaindustries/controller/POStatusController.java +++ b/src/main/java/com/utopiaindustries/controller/POStatusController.java @@ -35,13 +35,12 @@ public class POStatusController { public String poReport(@RequestParam(value = "poName", required = false) String poName, @RequestParam(value = "size", required = false) String size, @RequestParam(value = "color", required = false) String color, + @RequestParam(value = "count", required = false, defaultValue = "100") Long count, Model model){ model.addAttribute("allSize",jobCardItemService.getAllSizesOFItems()); model.addAttribute("allColor",jobCardItemService.getAllColorOFItems()); - model.addAttribute("allPOs", reportingService.getAllPOs(poName, size, color)); - model.addAttribute("dw", reportingService.getPoItemsSizeOrColor(4, size, color)); - + model.addAttribute("allPOs", reportingService.getAllPOs(poName, size, color, count)); return "/reporting/po-report"; } diff --git a/src/main/java/com/utopiaindustries/controller/ReportingController.java b/src/main/java/com/utopiaindustries/controller/ReportingController.java index c34525b..3b1bc9a 100644 --- a/src/main/java/com/utopiaindustries/controller/ReportingController.java +++ b/src/main/java/com/utopiaindustries/controller/ReportingController.java @@ -78,27 +78,27 @@ public class ReportingController { } @GetMapping( value = "/cutting-report" ) - public String cuttingReport(@RequestParam(value = "job-card-id", required = false ) String jobCardId, @RequestParam(value = "accountId" , required = false) String accountId, @RequestParam(value = "start-date", required = false) String startDate, @RequestParam(value = "end-date", required = false) String endDate, Model model ){ + public String cuttingReport(@RequestParam(value = "job-card-id", required = false ) String jobCardId, @RequestParam(value = "accountId" , required = false) String accountId, @RequestParam(value = "start-date", required = false) String startDate, @RequestParam(value = "end-date", required = false) String endDate, @RequestParam(value = "count", required = false) Long count, Model model ){ LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); model.addAttribute("startDate", startDate1); model.addAttribute("endDate", endDate1); model.addAttribute("accounts", inventoryAccountService.getAllCuttingAccounts() ); - model.addAttribute("cutting",reportingService.getCuttingTableDetails(jobCardId, accountId, startDate1.toString(), endDate1.toString())); + model.addAttribute("cutting",reportingService.getCuttingTableDetails(jobCardId, accountId, startDate1.toString(), endDate1.toString(), count)); return "/reporting/cutting-report"; } @GetMapping( value = "/stitching-report" ) - public String stitchingReport(@RequestParam(value = "job-card-id", required = false ) String jobCardId, @RequestParam(value = "accountId" , required = false) String accountId, @RequestParam(value = "start-date", required = false) String startDate, @RequestParam(value = "end-date", required = false) String endDate, Model model ){ + public String stitchingReport(@RequestParam(value = "job-card-id", required = false ) String jobCardId, @RequestParam(value = "accountId" , required = false) String accountId, @RequestParam(value = "start-date", required = false) String startDate, @RequestParam(value = "end-date", required = false) String endDate, @RequestParam(value = "count", required = false) Long count, Model model ){ LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); model.addAttribute("startDate", startDate1); model.addAttribute("endDate", endDate1); model.addAttribute("accounts" , inventoryAccountService.findInventoryAccounts( 2L ) ); - model.addAttribute("stitching",reportingService.getStitchingDetails(jobCardId, accountId, startDate1.toString(), endDate1.toString())); + model.addAttribute("stitching",reportingService.getStitchingDetails(jobCardId, accountId, startDate1.toString(), endDate1.toString(), count)); return "/reporting/stitching-report"; } @@ -109,13 +109,14 @@ public class ReportingController { @RequestParam( value = "sku", required = false) String sku, @RequestParam( value = "startDate", required = false) String startDate, @RequestParam( value = "endDate", required = false) String endDate, + @RequestParam(value = "count", required = false) Long count, Model model ){ LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); model.addAttribute("startDate", startDate1); model.addAttribute("endDate", endDate1); - model.addAttribute("transactions", reportingService.stitchingItemsTransactions( jobCardId, accountId, sku, startDate1.toString(), endDate1.toString() )); + model.addAttribute("transactions", reportingService.stitchingItemsTransactions( jobCardId, accountId, sku, startDate1.toString(), endDate1.toString(), count )); return "/reporting/accounts-transaction-table"; } diff --git a/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java index e95e769..6f2c455 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java @@ -205,10 +205,6 @@ public class InventoryTransactionLegDAO { params.addValue("start_date", startDate ); params.addValue("end_date", endDate ); params.addValue("type", type ); - System.out.println("Start Date: " + startDate); - System.out.println("End Date: " + endDate); - - System.out.println("Params: " + params.getValues()); return namedParameterJdbcTemplate.query( SELECT_JOB_CARD_DATES , params, new InventoryTransactionLegRowMapper() ); } diff --git a/src/main/java/com/utopiaindustries/dao/ctp/PurchaseOrderCTPDao.java b/src/main/java/com/utopiaindustries/dao/ctp/PurchaseOrderCTPDao.java index 3afe727..52203ff 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/PurchaseOrderCTPDao.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/PurchaseOrderCTPDao.java @@ -23,8 +23,8 @@ public class PurchaseOrderCTPDao { private final String TABLE_NAME = "cut_to_pack.purchase_order"; private final String SELECT_QUERY = String.format( "SELECT * FROM %s WHERE id = :id", TABLE_NAME ); - private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ", TABLE_NAME ); - private final String SELECT_BY_PO_CODE = String.format( "SELECT * FROM %s WHERE purchase_order_code = :purchase_order_code", TABLE_NAME ); + private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY created_at DESC LIMIT :limit ", TABLE_NAME ); + private final String SELECT_BY_PO_CODE = String.format("SELECT * FROM %s WHERE purchase_order_code = :purchase_order_code ORDER BY created_at DESC LIMIT :limit", TABLE_NAME); private final String DELETE_QUERY = String.format( "DELETE FROM %s WHERE id = :id", TABLE_NAME ); private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, purchase_order_code, purchase_order_quantity, purchase_order_quantity_required, article_name, created_by, status, po_status) " + @@ -70,8 +70,10 @@ public class PurchaseOrderCTPDao { // find all - public List findAll() { - return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new PurchaseOrderCTPRowMapper() ); + public List findAll(Long limit) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("limit", limit); + return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, params, new PurchaseOrderCTPRowMapper() ); } // save @@ -119,9 +121,10 @@ public class PurchaseOrderCTPDao { /* * find by po code * */ - public List findByPoCode(String poCode){ + public List findByPoCode(String poCode, Long limit ){ MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("purchase_order_code", poCode); + params.addValue("limit", limit); return namedParameterJdbcTemplate.query( SELECT_BY_PO_CODE, params, new PurchaseOrderCTPRowMapper() ); } diff --git a/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java b/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java index ff96091..18335ec 100644 --- a/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java +++ b/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java @@ -75,7 +75,7 @@ public class SummaryInventoryReportQueryBuilder { String startDate, String endDate, String type, - String parentDocumentType) { + String parentDocumentType, Long count) { QueryBuilder qb = new QueryBuilder() .setTable(TABLE_NAME) @@ -98,6 +98,7 @@ public class SummaryInventoryReportQueryBuilder { qb.and() .columnEquals("sku", sku ); } + qb.orderBy("transaction_leg_datetime", "DESC").limit(count); return qb.build(); } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/service/ReportingService.java b/src/main/java/com/utopiaindustries/service/ReportingService.java index 2cec9ef..3b5892a 100644 --- a/src/main/java/com/utopiaindustries/service/ReportingService.java +++ b/src/main/java/com/utopiaindustries/service/ReportingService.java @@ -440,15 +440,15 @@ public class ReportingService { /* * find all po for po-online-status * */ - public List getAllPOs(String poCode, String size, String color) { + public List getAllPOs(String poCode, String size, String color, Long count) { List pOsDetailsList = new ArrayList<>(); List purchaseOrderCTPList; if (poCode != null && !poCode.isEmpty()) { - purchaseOrderCTPList = purchaseOrderCTPDao.findByPoCode(poCode); + purchaseOrderCTPList = purchaseOrderCTPDao.findByPoCode(poCode, count); }else { - purchaseOrderCTPList = purchaseOrderCTPDao.findAll(); + purchaseOrderCTPList = purchaseOrderCTPDao.findAll(count); } @@ -482,7 +482,7 @@ public class ReportingService { actualProduction = actualProduction.add(jobCardItems.stream() .map(item -> Optional.ofNullable(item.getActualProduction()).orElse(BigDecimal.ZERO)) .reduce(BigDecimal.ZERO, BigDecimal::add)); - if(!jobCardItems.isEmpty() || (size == null || color == null)) { + if(!jobCardItems.isEmpty() || (StringUtils.isNullOrEmpty(size) || StringUtils.isNullOrEmpty(color))) { for (JobCardItem jobCardItem : jobCardItems) { //stitching detail @@ -634,7 +634,7 @@ public class ReportingService { return poItemsWrapperHashMap; } - public Map getCuttingTableDetails(String jobCardId, String cuttingTableId, String startDate, String endDate) { + public Map getCuttingTableDetails(String jobCardId, String cuttingTableId, String startDate, String endDate, Long count) { Map cuttingDetails = new HashMap<>(); long jobCardIdTemp = 0L; String startDate1 = null; @@ -659,7 +659,7 @@ public class ReportingService { inventoryAccountIds = List.of(Long.parseLong(cuttingTableId)); } - String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds, null, startDate1, endDate1, "IN","BUNDLE"); + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds, null, startDate1, endDate1, "IN","BUNDLE", count); List inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); Map dateWiseProduction = new TreeMap<>(); @@ -732,7 +732,7 @@ public class ReportingService { return cuttingDetails; } - public Map getStitchingDetails(String jobCardId, String stitchingLine, String startDate, String endDate) { + public Map getStitchingDetails(String jobCardId, String stitchingLine, String startDate, String endDate, Long count) { Map stitchingDetails = new HashMap<>(); long jobCardIdTemp = 0L; String startDate1 = null; @@ -757,7 +757,7 @@ public class ReportingService { inventoryAccountIds = List.of(Long.parseLong(stitchingLine)); } - String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds,null, startDate1, endDate1, "IN","STITCHING_OFFLINE"); + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds,null, startDate1, endDate1, "IN","STITCHING_OFFLINE", count); List inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); Map dateWiseProduction = new TreeMap<>(); @@ -831,7 +831,7 @@ public class ReportingService { return stitchingDetails; } - public List stitchingItemsTransactions(String jobCardId, String accountId, String sku, String startDate, String endDate) { + public List stitchingItemsTransactions(String jobCardId, String accountId, String sku, String startDate, String endDate, Long count) { List accountID = new ArrayList<>(); String startDate1 = null; String endDate1 = null; @@ -848,7 +848,7 @@ public class ReportingService { } - String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(Long.parseLong(jobCardId), accountID, sku, startDate1, endDate1,"IN","STITCHING_OFFLINE"); + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(Long.parseLong(jobCardId), accountID, sku, startDate1, endDate1,"IN","STITCHING_OFFLINE", count); List inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); List stitchingItemsList = inventoryTransactionLegs.stream() .map(InventoryTransactionLeg::getParentDocumentId) diff --git a/src/main/resources/templates/reporting/cutting-report-sidebar.html b/src/main/resources/templates/reporting/cutting-report-sidebar.html index 286ad48..080dbc6 100644 --- a/src/main/resources/templates/reporting/cutting-report-sidebar.html +++ b/src/main/resources/templates/reporting/cutting-report-sidebar.html @@ -32,6 +32,10 @@ +
+ + +
Reset diff --git a/src/main/resources/templates/reporting/cutting-report.html b/src/main/resources/templates/reporting/cutting-report.html index e8974fe..e4d320e 100644 --- a/src/main/resources/templates/reporting/cutting-report.html +++ b/src/main/resources/templates/reporting/cutting-report.html @@ -3,6 +3,17 @@ xmlns:ctp="http://www.w3.org/1999/xhtml"> +
@@ -33,8 +44,8 @@ class="p-0 text-center">
- - +
+ @@ -77,8 +88,37 @@ - - + + + + + - \ No newline at end of file + diff --git a/src/main/resources/templates/reporting/po-report-sidebar.html b/src/main/resources/templates/reporting/po-report-sidebar.html index 3d2b7ed..e8ba337 100644 --- a/src/main/resources/templates/reporting/po-report-sidebar.html +++ b/src/main/resources/templates/reporting/po-report-sidebar.html @@ -33,6 +33,10 @@ +
+ + +
Reset From b728efd3059168f52e139fbf787d62c37def8c49 Mon Sep 17 00:00:00 2001 From: "usama.jameel" Date: Mon, 30 Jun 2025 09:58:45 +0500 Subject: [PATCH 2/2] add logic when session expire redirect to login page --- .../reporting/po-jobcard-items-table.html | 2 +- .../templates/reporting/po-report.html | 19 ++++++++++++++++--- .../reporting/po-store-items-table.html | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/resources/templates/reporting/po-jobcard-items-table.html b/src/main/resources/templates/reporting/po-jobcard-items-table.html index 78fa7a8..6f3bf55 100644 --- a/src/main/resources/templates/reporting/po-jobcard-items-table.html +++ b/src/main/resources/templates/reporting/po-jobcard-items-table.html @@ -8,7 +8,7 @@
-
Job Card PO Number
+
diff --git a/src/main/resources/templates/reporting/po-report.html b/src/main/resources/templates/reporting/po-report.html index 801d47c..2652971 100644 --- a/src/main/resources/templates/reporting/po-report.html +++ b/src/main/resources/templates/reporting/po-report.html @@ -11,7 +11,7 @@

All PO's

Sku
+ class="table table-striped font-sm" data-order="[[ 0, "desc" ]]" style="min-width: 1500px;"> @@ -299,8 +299,21 @@ $.ajax({ url: `/ctp/po-status/po-items?poId=${poId}&size=${size}&color=${color}`, success: function( data ){ - // show fetched page - $row.child( data ).show(); + if (data.includes('page-login') || + data.includes('login__form') || + data.includes('Sign in')) { + // Redirect to login page + window.location.href = '/ctp/login?logout'; + } else { + $row.child(data).show(); + } + }, + error: function(xhr) { + if (xhr.status === 401) { + window.location.href = '/ctp/login?logout'; + } else { + $row.child('Error loading data').show(); + } } }); } diff --git a/src/main/resources/templates/reporting/po-store-items-table.html b/src/main/resources/templates/reporting/po-store-items-table.html index c8a180d..2e72a07 100644 --- a/src/main/resources/templates/reporting/po-store-items-table.html +++ b/src/main/resources/templates/reporting/po-store-items-table.html @@ -8,7 +8,7 @@
-
PO Number
+