diff --git a/src/main/java/com/utopiaindustries/controller/ReportingController.java b/src/main/java/com/utopiaindustries/controller/ReportingController.java index 07141d2..99d85bc 100644 --- a/src/main/java/com/utopiaindustries/controller/ReportingController.java +++ b/src/main/java/com/utopiaindustries/controller/ReportingController.java @@ -95,6 +95,36 @@ public class ReportingController { 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 ){ + + 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())); + + return "/reporting/stitching-report"; + } + + @GetMapping( "/inventory-transactions" ) + public String getInventoryTransactionsByAccount( @RequestParam( value = "account-id", required = false) String accountId, + @RequestParam( value = "jobCard-id", required = false) String jobCardId, + @RequestParam( value = "sku", required = false) String sku, + @RequestParam( value = "startDate", required = false) String startDate, + @RequestParam( value = "endDate", required = false) String endDate, + 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() )); + return "/reporting/accounts-transaction-table"; + } + + private ArrayList generateDateList(LocalDate start, LocalDate end) { ArrayList localDates = new ArrayList<>(); while (start.isBefore(end)) { diff --git a/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java index 007a50b..dd285e1 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java +++ b/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java @@ -4,7 +4,7 @@ public class CuttingJobCardItemWrapper { private long jobCardId; private String poName; private String sku; - private Long totalCutting; + private Long total; private String width; private String length; private String gsm; @@ -13,8 +13,8 @@ public class CuttingJobCardItemWrapper { private String articleName; private boolean isComplete; private String jobCardCode; - private String cuttingOperatorName; - private long cuttingAccountId; + private String operatorName; + private long accountId; public long getJobCardId() { return jobCardId; @@ -40,14 +40,6 @@ public class CuttingJobCardItemWrapper { this.sku = sku; } - public Long getTotalCutting() { - return totalCutting; - } - - public void setTotalCutting(Long totalCutting) { - this.totalCutting = totalCutting; - } - public String getWidth() { return width; } @@ -104,13 +96,6 @@ public class CuttingJobCardItemWrapper { this.jobCardCode = jobCardCode; } - public long getCuttingAccountId() { - return cuttingAccountId; - } - - public void setCuttingAccountId(long cuttingAccountId) { - this.cuttingAccountId = cuttingAccountId; - } public String getLength() { return length; @@ -120,31 +105,47 @@ public class CuttingJobCardItemWrapper { this.length = length; } - public String getCuttingOperatorName() { - return cuttingOperatorName; + public String getOperatorName() { + return operatorName; } - public void setCuttingOperatorName(String cuttingOperatorName) { - this.cuttingOperatorName = cuttingOperatorName; + public void setOperatorName(String operatorName) { + this.operatorName = operatorName; + } + + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + + public Long getTotal() { + return total; + } + + public void setTotal(Long total) { + this.total = total; } @Override public String toString() { return "CuttingJobCardItemWrapper{" + - "cuttingAccountId=" + cuttingAccountId + - ", cuttingOperatorName='" + cuttingOperatorName + '\'' + - ", jobCardCode='" + jobCardCode + '\'' + - ", isComplete=" + isComplete + - ", articleName='" + articleName + '\'' + - ", ply='" + ply + '\'' + - ", wtPly='" + wtPly + '\'' + - ", gsm='" + gsm + '\'' + - ", length='" + length + '\'' + - ", width='" + width + '\'' + - ", totalCutting=" + totalCutting + - ", sku='" + sku + '\'' + + "jobCardId=" + jobCardId + ", poName='" + poName + '\'' + - ", jobCardId=" + jobCardId + + ", sku='" + sku + '\'' + + ", total=" + total + + ", width='" + width + '\'' + + ", length='" + length + '\'' + + ", gsm='" + gsm + '\'' + + ", wtPly='" + wtPly + '\'' + + ", ply='" + ply + '\'' + + ", articleName='" + articleName + '\'' + + ", isComplete=" + isComplete + + ", jobCardCode='" + jobCardCode + '\'' + + ", operatorName='" + operatorName + '\'' + + ", accountId=" + accountId + '}'; } } diff --git a/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java b/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java index caad229..ff96091 100644 --- a/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java +++ b/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java @@ -71,8 +71,11 @@ public class SummaryInventoryReportQueryBuilder { public static String cuttingQueryBuild(long jobCardId, List account, + String sku, String startDate, - String endDate,String type) { + String endDate, + String type, + String parentDocumentType) { QueryBuilder qb = new QueryBuilder() .setTable(TABLE_NAME) @@ -84,11 +87,17 @@ public class SummaryInventoryReportQueryBuilder { .and() .columnEqualToOrLessThan("transaction_leg_datetime",endDate) .and() - .columnEquals("type",type); + .columnEquals("type",type) + .and() + .columnEquals("parent_document_type",parentDocumentType); if (jobCardId != 0){ qb.and() .columnEquals("job_card_id", jobCardId ); } + if (!StringUtils.isNullOrEmpty(sku)){ + qb.and() + .columnEquals("sku", sku ); + } return qb.build(); } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/service/BarcodeService.java b/src/main/java/com/utopiaindustries/service/BarcodeService.java index b69a4ea..f4c01e1 100644 --- a/src/main/java/com/utopiaindustries/service/BarcodeService.java +++ b/src/main/java/com/utopiaindustries/service/BarcodeService.java @@ -351,13 +351,18 @@ public class BarcodeService { PdfFont font = PdfFontFactory.createFont(StandardFonts.COURIER_OBLIQUE); String id = String.valueOf(artifact.getId()); + float textSize = stickerSize.getTextSize() + 8; + float charWidth = textSize * 0.6f; + float idWidth = id.length() * charWidth; + float xCentered = (labelWidth / 2f) - (idWidth / 2f); + document.add(new Paragraph(id) .setFont(font) .setBold() .setFontColor(ColorConstants.BLACK) - .setFontSize(stickerSize.getTextSize() + 8) - .setTextAlignment(TextAlignment.LEFT) - .setFixedPosition(textX - 25, textY + 13, 100)); + .setFontSize(textSize) + .setFixedPosition(xCentered, textY + 13, 100)); + float dottedLine = textY - 65; for(int i= 0 ;i<16;i++){ diff --git a/src/main/java/com/utopiaindustries/service/ReportingService.java b/src/main/java/com/utopiaindustries/service/ReportingService.java index c804ef6..4177800 100644 --- a/src/main/java/com/utopiaindustries/service/ReportingService.java +++ b/src/main/java/com/utopiaindustries/service/ReportingService.java @@ -618,7 +618,7 @@ public class ReportingService { inventoryAccountIds = List.of(Long.parseLong(cuttingTableId)); } - String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds, startDate1, endDate1, "IN"); + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds, null, startDate1, endDate1, "IN","BUNDLE"); List inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); Map dateWiseProduction = new TreeMap<>(); @@ -670,15 +670,15 @@ public class ReportingService { wrapper.setGsm(item.getGsm()); wrapper.setPly(item.getPly()); wrapper.setSku(item.getSku()); - wrapper.setTotalCutting(item.getActualProduction().longValue()); + wrapper.setTotal(item.getActualProduction().longValue()); wrapper.setWidth(item.getWidth()); wrapper.setWtPly(item.getWtPly()); wrapper.setComplete(item.isComplete()); wrapper.setPoName(jobCard.getPurchaseOrderId()); - wrapper.setCuttingOperatorName(bundle.getCreatedBy()); + wrapper.setOperatorName(bundle.getCreatedBy()); wrapper.setJobCardId(item.getJobCardId()); wrapper.setLength(item.getLength()); - wrapper.setCuttingAccountId(accountId); + wrapper.setAccountId(accountId); return wrapper; }).collect(Collectors.toList()); @@ -691,6 +691,131 @@ public class ReportingService { return cuttingDetails; } + public Map getStitchingDetails(String jobCardId, String stitchingLine, String startDate, String endDate) { + Map stitchingDetails = new HashMap<>(); + long jobCardIdTemp = 0L; + String startDate1 = null; + String endDate1 = null; + + if (!StringUtils.isNullOrEmpty(startDate)) { + String formattedStart = CTPDateTimeFormat.getMySQLFormattedDateString(startDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT); + String formattedEnd = !StringUtils.isNullOrEmpty(endDate) + ? CTPDateTimeFormat.getMySQLFormattedDateString(endDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT) + : LocalDate.now().toString(); + + startDate1 = String.format("'%s 00:00:01'", formattedStart); + endDate1 = String.format("'%s 23:59:59'", formattedEnd); + } + + List inventoryAccounts = inventoryAccountDAO.findByParentEntityTypeAndParentId("PROCESS", 2L); + List inventoryAccountIds = inventoryAccounts.stream().map(InventoryAccount::getId).collect(Collectors.toList()); + + if (!StringUtils.isNullOrEmpty(jobCardId)) { + jobCardIdTemp = Long.parseLong(jobCardId); + } else if (!StringUtils.isNullOrEmpty(stitchingLine)) { + inventoryAccountIds = List.of(Long.parseLong(stitchingLine)); + } + + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds,null, startDate1, endDate1, "IN","STITCHING_OFFLINE"); + List inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); + + Map dateWiseProduction = new TreeMap<>(); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); + + Map> dateWiseJobCardIds = inventoryTransactionLegs.stream() + .filter(e -> e.getTransactionLegDateTime() != null && e.getJobCardId() != 0) + .collect(Collectors.groupingBy( + e -> e.getTransactionLegDateTime().toLocalDate(), + Collectors.mapping(InventoryTransactionLeg::getJobCardId, Collectors.toList()) + )); + + for (Map.Entry> entry : dateWiseJobCardIds.entrySet()) { + LocalDate date = entry.getKey(); + List jobCardIds = entry.getValue(); + + if (!jobCardIds.isEmpty()) { + int totalProduction = inventoryTransactionLegs.stream() + .filter(item -> jobCardIds.contains(item.getJobCardId()) && + "STITCHING_OFFLINE".equals(item.getParentDocumentType()) && item.getTransactionLegDateTime().toLocalDate().equals(date)) + .mapToInt(item -> item.getQuantity().intValue()) + .sum(); + + dateWiseProduction.put(date.format(formatter), totalProduction); + } + } + + List distinctJobCardIds = inventoryTransactionLegs.stream() + .map(InventoryTransactionLeg::getJobCardId) + .filter(id -> id != 0) + .distinct() + .collect(Collectors.toList()); + + Map> jobCardItemsStitchingDetailsMap = new HashMap<>(); + Map totalStitchingBasedOnAccountID = new HashMap<>(); + + for (long jobCardIdEntry : distinctJobCardIds) { + Long accountId = inventoryTransactionLegs.stream() + .filter(e -> e.getJobCardId() == jobCardIdEntry) + .map(e -> e.getAccountId().longValue()) + .findFirst() + .orElse(0L); + + JobCard jobCard = jobCardDAO.find(jobCardIdEntry); + List stitchingOfflineItem = stitchingOfflineItemDAO.findByJobCardId(jobCardIdEntry); + + List jobCardItems = jobCardItemDAO.findByCardId(jobCardIdEntry); + + List wrappers = jobCardItems.stream().map(item -> { + CuttingJobCardItemWrapper wrapper = new CuttingJobCardItemWrapper(); + wrapper.setArticleName(jobCard.getArticleName()); + wrapper.setJobCardCode(jobCard.getCode()); + wrapper.setSku(item.getSku()); + wrapper.setPoName(jobCard.getPurchaseOrderId()); + wrapper.setJobCardId(item.getJobCardId()); + wrapper.setOperatorName(stitchingOfflineItem.get(0).getCreatedBy()); + wrapper.setAccountId(accountId); + return wrapper; + + }).collect(Collectors.toList()); + totalStitchingBasedOnAccountID.put(jobCard.getId()+stitchingOfflineItem.get(0).getSku(), stitchingOfflineItem.size()); + jobCardItemsStitchingDetailsMap.computeIfAbsent(accountId, k -> new ArrayList<>()).addAll(wrappers); + } + + System.out.println(jobCardItemsStitchingDetailsMap); + System.out.println(totalStitchingBasedOnAccountID); + + stitchingDetails.put("totalStitchingBasedOnAccountID", totalStitchingBasedOnAccountID); + stitchingDetails.put("jobCardItemsStitchingDetailsMap", jobCardItemsStitchingDetailsMap); + stitchingDetails.put("Date Wise Stitching", dateWiseProduction); + + stitchingDetails.put("stitchingAccount", inventoryAccounts); + return stitchingDetails; + } + + public List stitchingItemsTransactions(String jobCardId, String accountId, String sku, String startDate, String endDate) { + List accountID = new ArrayList<>(); + String startDate1 = null; + String endDate1 = null; + + if (!StringUtils.isNullOrEmpty(startDate) && !StringUtils.isNullOrEmpty(accountId) && !StringUtils.isNullOrEmpty(jobCardId)) { + String formattedStart = CTPDateTimeFormat.getMySQLFormattedDateString(startDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT); + String formattedEnd = !StringUtils.isNullOrEmpty(endDate) + ? CTPDateTimeFormat.getMySQLFormattedDateString(endDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT) + : LocalDate.now().toString(); + + startDate1 = String.format("'%s 00:00:01'", formattedStart); + endDate1 = String.format("'%s 23:59:59'", formattedEnd); + accountID.add(Long.parseLong(accountId)); + } + + + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(Long.parseLong(jobCardId), accountID, sku, startDate1, endDate1,"IN","STITCHING_OFFLINE"); + List inventoryTransactionLegs = inventoryTransactionLegDAO.findByQuery(query); + List stitchingItemsList = inventoryTransactionLegs.stream() + .map(InventoryTransactionLeg::getParentDocumentId) + .collect(Collectors.toList()); + return stitchingOfflineItemDAO.findByIds(stitchingItemsList); + } private StringBuilder generateTime(LocalDateTime startDate, LocalDateTime endDate){ StringBuilder totalTime = new StringBuilder(); diff --git a/src/main/resources/static/js/charts.js b/src/main/resources/static/js/charts.js index 13cc674..f0dfc24 100644 --- a/src/main/resources/static/js/charts.js +++ b/src/main/resources/static/js/charts.js @@ -137,65 +137,69 @@ document.addEventListener("DOMContentLoaded", function () { }); } - function createSingleBarChart(divId, height, width, title,Heading, Data, dates, fontSize, maxValue) { - if (!document.getElementById(divId)) { - return; - } - Highcharts.chart(divId, { - chart: { - type: 'column', - height: height, - width: width, - }, - title: { - text: title, - align: 'center', - verticalAlign: 'top', - y: 30, - style: { - fontSize: fontSize, - fontWeight: 'bold', - } - }, - xAxis: { - categories: dates, - labels: { - rotation: -45, - style: { - fontSize: 10-fontSize, - fontWeight: 'bold' - } - } - }, - yAxis: { - min: 0, - max: maxValue, - softMax: maxValue, - softMin: 0, - startOnTick: true, - endOnTick: true, - title: { - text: 'Total Progress', - style: { - fontSize: fontSize, - fontWeight: 'bold', - } - }, - labels: { - format: '{value}%' - } - }, - - scrollbar: { - enabled: true - }, - series: [{ - name: Heading, - data: Data - }] - }); - } - + function createSingleBarChart(divId, height, width, title,Heading, Data, dates, fontSize, maxValue) { + if (!document.getElementById(divId)) { + return; + } + Highcharts.chart(divId, { + chart: { + type: 'column', + height: height, + width: width, + }, + title: { + text: title, + align: 'center', + verticalAlign: 'top', + y: 30, + style: { + fontSize: fontSize, + fontWeight: 'bold', + } + }, + xAxis: { + categories: dates, + labels: { + rotation: -45, + style: { + fontSize: 10-fontSize, + fontWeight: 'bold' + } + } + }, + yAxis: { + min: 0, + max: maxValue, + softMax: maxValue, + softMin: 0, + startOnTick: true, + endOnTick: true, + title: { + text: 'Total Progress', + style: { + fontSize: fontSize, + fontWeight: 'bold', + } + }, + labels: { + format: '{value}%' + } + }, + legend: { + itemStyle: { + fontSize: 10-fontSize, + fontWeight: 'bold' + } + }, + scrollbar: { + enabled: true + }, + series: [{ + name: Heading, + data: Data + }] + }); + } initializeGauges(); function initializeGauges() { @@ -256,7 +260,7 @@ document.addEventListener("DOMContentLoaded", function () { createBarChart( divId, height, width, title, aHeading, aData, bHeading, bData, cHeading, cData, dHeading, dData, datesArray, fontSize, maxValue); }); - const cuttingBarChart = document.querySelectorAll('.cuttingBarChart'); + const cuttingBarChart = document.querySelectorAll('.singleBarChart'); cuttingBarChart.forEach(function (div) { const title = div.getAttribute('data-title'); const height = div.getAttribute('data-height'); diff --git a/src/main/resources/templates/_fragments.html b/src/main/resources/templates/_fragments.html index 4635a1d..8569108 100644 --- a/src/main/resources/templates/_fragments.html +++ b/src/main/resources/templates/_fragments.html @@ -144,6 +144,10 @@ th:classappend="${#strings.startsWith(#httpServletRequest.getRequestURI(), '/ctp/reporting/cutting-report') ? 'active' : ''}"> Cutting Tables Report +