add pagination in cutting report and count in reporting sidebars

pull/37/head
usama.jameel 2025-06-26 12:20:56 +05:00
parent b3b5597313
commit 59b572d691
9 changed files with 81 additions and 33 deletions

View File

@ -35,13 +35,12 @@ public class POStatusController {
public String poReport(@RequestParam(value = "poName", required = false) String poName, public String poReport(@RequestParam(value = "poName", required = false) String poName,
@RequestParam(value = "size", required = false) String size, @RequestParam(value = "size", required = false) String size,
@RequestParam(value = "color", required = false) String color, @RequestParam(value = "color", required = false) String color,
@RequestParam(value = "count", required = false, defaultValue = "100") Long count,
Model model){ Model model){
model.addAttribute("allSize",jobCardItemService.getAllSizesOFItems()); model.addAttribute("allSize",jobCardItemService.getAllSizesOFItems());
model.addAttribute("allColor",jobCardItemService.getAllColorOFItems()); model.addAttribute("allColor",jobCardItemService.getAllColorOFItems());
model.addAttribute("allPOs", reportingService.getAllPOs(poName, size, color)); model.addAttribute("allPOs", reportingService.getAllPOs(poName, size, color, count));
model.addAttribute("dw", reportingService.getPoItemsSizeOrColor(4, size, color));
return "/reporting/po-report"; return "/reporting/po-report";
} }

View File

@ -78,27 +78,27 @@ public class ReportingController {
} }
@GetMapping( value = "/cutting-report" ) @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 startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate);
LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate);
model.addAttribute("startDate", startDate1); model.addAttribute("startDate", startDate1);
model.addAttribute("endDate", endDate1); model.addAttribute("endDate", endDate1);
model.addAttribute("accounts", inventoryAccountService.getAllCuttingAccounts() ); 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"; return "/reporting/cutting-report";
} }
@GetMapping( value = "/stitching-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 startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate);
LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate);
model.addAttribute("startDate", startDate1); model.addAttribute("startDate", startDate1);
model.addAttribute("endDate", endDate1); model.addAttribute("endDate", endDate1);
model.addAttribute("accounts" , inventoryAccountService.findInventoryAccounts( 2L ) ); 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"; return "/reporting/stitching-report";
} }
@ -109,13 +109,14 @@ public class ReportingController {
@RequestParam( value = "sku", required = false) String sku, @RequestParam( value = "sku", required = false) String sku,
@RequestParam( value = "startDate", required = false) String startDate, @RequestParam( value = "startDate", required = false) String startDate,
@RequestParam( value = "endDate", required = false) String endDate, @RequestParam( value = "endDate", required = false) String endDate,
@RequestParam(value = "count", required = false) Long count,
Model model ){ Model model ){
LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate); LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(31) : LocalDate.parse(startDate);
LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate);
model.addAttribute("startDate", startDate1); model.addAttribute("startDate", startDate1);
model.addAttribute("endDate", endDate1); 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"; return "/reporting/accounts-transaction-table";
} }

View File

@ -205,10 +205,6 @@ public class InventoryTransactionLegDAO {
params.addValue("start_date", startDate ); params.addValue("start_date", startDate );
params.addValue("end_date", endDate ); params.addValue("end_date", endDate );
params.addValue("type", type ); 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() ); return namedParameterJdbcTemplate.query( SELECT_JOB_CARD_DATES , params, new InventoryTransactionLegRowMapper() );
} }

View File

@ -23,8 +23,8 @@ public class PurchaseOrderCTPDao {
private final String TABLE_NAME = "cut_to_pack.purchase_order"; 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_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_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", 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 DELETE_QUERY = String.format( "DELETE FROM %s WHERE id = :id", TABLE_NAME );
private final String INSERT_QUERY = String.format( 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) " + "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 // find all
public List<PurchaseOrderCTP> findAll() { public List<PurchaseOrderCTP> findAll(Long limit) {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new PurchaseOrderCTPRowMapper() ); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("limit", limit);
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, params, new PurchaseOrderCTPRowMapper() );
} }
// save // save
@ -119,9 +121,10 @@ public class PurchaseOrderCTPDao {
/* /*
* find by po code * find by po code
* */ * */
public List<PurchaseOrderCTP> findByPoCode(String poCode){ public List<PurchaseOrderCTP> findByPoCode(String poCode, Long limit ){
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("purchase_order_code", poCode); params.addValue("purchase_order_code", poCode);
params.addValue("limit", limit);
return namedParameterJdbcTemplate.query( SELECT_BY_PO_CODE, params, new PurchaseOrderCTPRowMapper() ); return namedParameterJdbcTemplate.query( SELECT_BY_PO_CODE, params, new PurchaseOrderCTPRowMapper() );
} }

View File

@ -75,7 +75,7 @@ public class SummaryInventoryReportQueryBuilder {
String startDate, String startDate,
String endDate, String endDate,
String type, String type,
String parentDocumentType) { String parentDocumentType, Long count) {
QueryBuilder qb = new QueryBuilder() QueryBuilder qb = new QueryBuilder()
.setTable(TABLE_NAME) .setTable(TABLE_NAME)
@ -98,6 +98,7 @@ public class SummaryInventoryReportQueryBuilder {
qb.and() qb.and()
.columnEquals("sku", sku ); .columnEquals("sku", sku );
} }
qb.orderBy("transaction_leg_datetime", "DESC").limit(count);
return qb.build(); return qb.build();
} }
} }

View File

@ -440,15 +440,15 @@ public class ReportingService {
/* /*
* find all po for po-online-status * find all po for po-online-status
* */ * */
public List<POsDetails> getAllPOs(String poCode, String size, String color) { public List<POsDetails> getAllPOs(String poCode, String size, String color, Long count) {
List<POsDetails> pOsDetailsList = new ArrayList<>(); List<POsDetails> pOsDetailsList = new ArrayList<>();
List<PurchaseOrderCTP> purchaseOrderCTPList; List<PurchaseOrderCTP> purchaseOrderCTPList;
if (poCode != null && !poCode.isEmpty()) { if (poCode != null && !poCode.isEmpty()) {
purchaseOrderCTPList = purchaseOrderCTPDao.findByPoCode(poCode); purchaseOrderCTPList = purchaseOrderCTPDao.findByPoCode(poCode, count);
}else { }else {
purchaseOrderCTPList = purchaseOrderCTPDao.findAll(); purchaseOrderCTPList = purchaseOrderCTPDao.findAll(count);
} }
@ -482,7 +482,7 @@ public class ReportingService {
actualProduction = actualProduction.add(jobCardItems.stream() actualProduction = actualProduction.add(jobCardItems.stream()
.map(item -> Optional.ofNullable(item.getActualProduction()).orElse(BigDecimal.ZERO)) .map(item -> Optional.ofNullable(item.getActualProduction()).orElse(BigDecimal.ZERO))
.reduce(BigDecimal.ZERO, BigDecimal::add)); .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) { for (JobCardItem jobCardItem : jobCardItems) {
//stitching detail //stitching detail
@ -634,7 +634,7 @@ public class ReportingService {
return poItemsWrapperHashMap; return poItemsWrapperHashMap;
} }
public Map<String, Object> getCuttingTableDetails(String jobCardId, String cuttingTableId, String startDate, String endDate) { public Map<String, Object> getCuttingTableDetails(String jobCardId, String cuttingTableId, String startDate, String endDate, Long count) {
Map<String, Object> cuttingDetails = new HashMap<>(); Map<String, Object> cuttingDetails = new HashMap<>();
long jobCardIdTemp = 0L; long jobCardIdTemp = 0L;
String startDate1 = null; String startDate1 = null;
@ -659,7 +659,7 @@ public class ReportingService {
inventoryAccountIds = List.of(Long.parseLong(cuttingTableId)); 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<InventoryTransactionLeg> inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); List<InventoryTransactionLeg> inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query);
Map<String, Integer> dateWiseProduction = new TreeMap<>(); Map<String, Integer> dateWiseProduction = new TreeMap<>();
@ -732,7 +732,7 @@ public class ReportingService {
return cuttingDetails; return cuttingDetails;
} }
public Map<String, Object> getStitchingDetails(String jobCardId, String stitchingLine, String startDate, String endDate) { public Map<String, Object> getStitchingDetails(String jobCardId, String stitchingLine, String startDate, String endDate, Long count) {
Map<String, Object> stitchingDetails = new HashMap<>(); Map<String, Object> stitchingDetails = new HashMap<>();
long jobCardIdTemp = 0L; long jobCardIdTemp = 0L;
String startDate1 = null; String startDate1 = null;
@ -757,7 +757,7 @@ public class ReportingService {
inventoryAccountIds = List.of(Long.parseLong(stitchingLine)); 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<InventoryTransactionLeg> inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); List<InventoryTransactionLeg> inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query);
Map<String, Integer> dateWiseProduction = new TreeMap<>(); Map<String, Integer> dateWiseProduction = new TreeMap<>();
@ -831,7 +831,7 @@ public class ReportingService {
return stitchingDetails; return stitchingDetails;
} }
public List<StitchingOfflineItem> stitchingItemsTransactions(String jobCardId, String accountId, String sku, String startDate, String endDate) { public List<StitchingOfflineItem> stitchingItemsTransactions(String jobCardId, String accountId, String sku, String startDate, String endDate, Long count) {
List<Long> accountID = new ArrayList<>(); List<Long> accountID = new ArrayList<>();
String startDate1 = null; String startDate1 = null;
String endDate1 = 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<InventoryTransactionLeg> inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); List<InventoryTransactionLeg> inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query);
List<Long> stitchingItemsList = inventoryTransactionLegs.stream() List<Long> stitchingItemsList = inventoryTransactionLegs.stream()
.map(InventoryTransactionLeg::getParentDocumentId) .map(InventoryTransactionLeg::getParentDocumentId)

View File

@ -32,6 +32,10 @@
</option> </option>
</select> </select>
</div> </div>
<div class="form-group">
<label>Count</label>
<input type="number" class="form-control" name="count" maxlength="100" min="0" th:value="${param['count'] ?: 100}">
</div>
<input type="submit" class="btn btn-secondary btn-block" value="Search"> <input type="submit" class="btn btn-secondary btn-block" value="Search">
<a th:href="@{${#strings.replace(#httpServletRequest.requestURI, #request.getContextPath(), '')}}" <a th:href="@{${#strings.replace(#httpServletRequest.requestURI, #request.getContextPath(), '')}}"
class="btn btn-secondary btn-block">Reset</a> class="btn btn-secondary btn-block">Reset</a>

View File

@ -3,6 +3,17 @@
xmlns:ctp="http://www.w3.org/1999/xhtml"> xmlns:ctp="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head('Cutting Report')"></head> <head th:replace="_fragments :: head('Cutting Report')"></head>
<style>
div.dataTables_wrapper div.dataTables_filter {
text-align: left !important;
}
div.dataTables_wrapper .dt-buttons {
text-align: left !important;
}
div.dataTables_wrapper div.dataTables_info {
text-align: left !important;
}
</style>
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
@ -33,8 +44,8 @@
class="p-0 text-center"> class="p-0 text-center">
<div class="bg-dark text-white py-2 px-3 fs-5 fw-bold text-center" <div class="bg-dark text-white py-2 px-3 fs-5 fw-bold text-center"
th:text="${cuttingAccount.title}"></div> th:text="${cuttingAccount.title}"></div>
<table class="table table-bordered mt-2"> <table class="table table-bordered mt-2 datatable">
<thead class=""> <thead>
<tr> <tr>
<th>Job Card</th> <th>Job Card</th>
<th>PO Number</th> <th>PO Number</th>
@ -77,8 +88,37 @@
</div> </div>
</main> </main>
</div> </div>
<!-- Load chart logic -->
<!-- Load JavaScript file -->
<script th:src="@{/js/charts.js}"></script> <script th:src="@{/js/charts.js}"></script>
<!-- DataTables Initialization -->
<script>
const dataTableConfig = {
pageLength: 5,
searching: true,
lengthChange: false,
processing: false,
info: true,
paging: true,
dom: `
<'row mb-2 mt-2'<'col-sm-6'f><'col-sm-6'B>>
<'row'<'col-sm-12'tr>>
<'row mt-2'<'col-sm-6'i><'col-sm-6 text-end'p>>`
,
buttons: []
};
$(document).ready(function () {
$('table.datatable').each(function () {
const $table = $(this);
if (!$.fn.DataTable.isDataTable($table)) {
$table.DataTable(dataTableConfig);
}
});
});
</script>
</body> </body>
</html> </html>

View File

@ -33,6 +33,10 @@
</option> </option>
</select> </select>
</div> </div>
<div class="form-group">
<label>Count</label>
<input type="number" class="form-control" name="count" maxlength="100" min="0" th:value="${param['count'] ?: 100}">
</div>
<input type="submit" class="btn btn-secondary btn-block" value="Search"> <input type="submit" class="btn btn-secondary btn-block" value="Search">
<a th:href="@{${#strings.replace(#httpServletRequest.requestURI, #request.getContextPath(), '')}}" <a th:href="@{${#strings.replace(#httpServletRequest.requestURI, #request.getContextPath(), '')}}"
class="btn btn-secondary btn-block">Reset</a> class="btn btn-secondary btn-block">Reset</a>