diff --git a/pom.xml b/pom.xml index afc29ab..24912a3 100644 --- a/pom.xml +++ b/pom.xml @@ -395,7 +395,7 @@ -Xms1024m -Xmx8g - org.apache.maven.pluginsmaven-compiler-plugin88 + org.apache.maven.pluginsmaven-compiler-plugin99 diff --git a/src/main/java/com/utopiaindustries/controller/ReportingController.java b/src/main/java/com/utopiaindustries/controller/ReportingController.java index 2aaf425..07141d2 100644 --- a/src/main/java/com/utopiaindustries/controller/ReportingController.java +++ b/src/main/java/com/utopiaindustries/controller/ReportingController.java @@ -1,9 +1,8 @@ package com.utopiaindustries.controller; -import com.utopiaindustries.auth.CuttingRole; import com.utopiaindustries.auth.ReportingRole; -import com.utopiaindustries.model.ctp.JobCardItem; import com.utopiaindustries.model.ctp.SummaryInventoryReport; +import com.utopiaindustries.service.InventoryAccountService; import com.utopiaindustries.service.ReportingService; import com.utopiaindustries.service.SummaryInventoryReportService; import com.utopiaindustries.util.StringUtils; @@ -19,7 +18,6 @@ import java.time.LocalDate; import java.util.ArrayList; import java.util.List; import java.util.Map; -import java.util.stream.Collectors; @Controller @ReportingRole @@ -27,10 +25,13 @@ import java.util.stream.Collectors; public class ReportingController { private final ReportingService reportingService; private final SummaryInventoryReportService summaryInventoryReportService; + private final InventoryAccountService inventoryAccountService; - public ReportingController(SummaryInventoryReportService summaryInventoryReportService2, ReportingService reportingService) { + + public ReportingController(SummaryInventoryReportService summaryInventoryReportService2, ReportingService reportingService, InventoryAccountService inventoryAccountService) { this.summaryInventoryReportService = summaryInventoryReportService2; this.reportingService = reportingService; + this.inventoryAccountService = inventoryAccountService; } @GetMapping( "/summary") @@ -68,8 +69,9 @@ public class ReportingController { } @GetMapping( "/po-report") - public String poReport( Model model){ - model.addAttribute("allPOs", reportingService.getAllPOs()); + public String poReport(@RequestParam(value = "poName", required = false) String poName, Model model){ + + model.addAttribute("allPOs", reportingService.getAllPOs(poName)); return "/reporting/po-report"; } @@ -80,6 +82,19 @@ public class ReportingController { return "/reporting/po-job-card-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 ){ + + 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())); + + return "/reporting/cutting-report"; + } + private ArrayList generateDateList(LocalDate start, LocalDate end) { ArrayList localDates = new ArrayList<>(); while (start.isBefore(end)) { diff --git a/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java index 8c15a7b..3ec92a8 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/InventoryTransactionLegDAO.java @@ -1,9 +1,9 @@ package com.utopiaindustries.dao.ctp; -import com.utopiaindustries.model.ctp.Bundle; import com.utopiaindustries.model.ctp.InventorySummary; import com.utopiaindustries.model.ctp.InventoryTransactionLeg; import com.utopiaindustries.util.KeyHolderFunctions; +import com.utopiaindustries.util.StringUtils; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.support.GeneratedKeyHolder; @@ -55,6 +55,10 @@ public class InventoryTransactionLegDAO { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; } + public List findByQuery(String query ){ + return namedParameterJdbcTemplate.query( query, new InventoryTransactionLegRowMapper() ); + } + // prepare query params private MapSqlParameterSource prepareInsertQueryParams( InventoryTransactionLeg inventoryTransactionLeg ) { MapSqlParameterSource params = new MapSqlParameterSource(); diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java index 71a3b85..04e539b 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java @@ -23,10 +23,10 @@ public class JobCardDAO { private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id DESC", TABLE_NAME ); private final String SELECT_ALL_QUERY_WITH_LIMIT = String.format( "SELECT * FROM %s ORDER BY id 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, code, job_order_id, created_at, created_by, status, inventory_status, customer, lot_number, purchase_order_id, location_site_id, description) VALUES (:id, :code, :job_order_id, :created_at, :created_by, :status, :inventory_status, :customer, :lot_number, :purchase_order_id, :location_site_id, :description) ON DUPLICATE KEY UPDATE code = VALUES(code), job_order_id = VALUES(job_order_id), created_at = VALUES(created_at), created_by = VALUES(created_by), status = VALUES(status), inventory_status = VALUES(inventory_status), customer = VALUES(customer), lot_number = VALUES(lot_number), purchase_order_id = VALUES(purchase_order_id), location_site_id = VALUES(location_site_id), description = VALUES(description)", TABLE_NAME ); + private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, code, job_order_id, created_at, created_by, status, inventory_status, customer, lot_number, purchase_order_id, location_site_id, description, poQuantity, articleName) VALUES (:id, :code, :job_order_id, :created_at, :created_by, :status, :inventory_status, :customer, :lot_number, :purchase_order_id, :location_site_id, :description, :poQuantity, :articleName) ON DUPLICATE KEY UPDATE code = VALUES(code), job_order_id = VALUES(job_order_id), created_at = VALUES(created_at), created_by = VALUES(created_by), status = VALUES(status), inventory_status = VALUES(inventory_status), customer = VALUES(customer), lot_number = VALUES(lot_number), purchase_order_id = VALUES(purchase_order_id), location_site_id = VALUES(location_site_id), description = VALUES(description), poQuantity = VALUES(poQuantity), articleName = VALUES(articleName) ", TABLE_NAME ); private final String SELECT_BY_LIKE_CODE_AND_INV_STATUS_AND_STATUS = String.format( "SELECT * FROM %s WHERE code like :code AND status = :status AND inventory_status = :inventory_status", TABLE_NAME ); private final String SELECT_BY_LIKE_CODE = String.format( "SELECT * FROM %s WHERE code like :code", TABLE_NAME ); - private final String SELECT_BY_LIMIT = String.format( "SELECT * FROM %s WHERE created_by = :created_by ORDER BY id DESC limit :limit", TABLE_NAME ); + private final String SELECT_BY_LIMIT = String.format( "SELECT * FROM %s WHERE created_by = :created_by ORDER BY id ASC limit :limit", TABLE_NAME ); // prepare query params private MapSqlParameterSource prepareInsertQueryParams( JobCard jobCard ) { @@ -39,6 +39,8 @@ public class JobCardDAO { .addValue("status", jobCard.getStatus() ) .addValue("inventory_status", jobCard.getInventoryStatus() ) .addValue("customer", jobCard.getCustomer() ) + .addValue("poQuantity", jobCard.getPoQuantity() ) + .addValue("articleName", jobCard.getArticleName() ) .addValue("lot_number", jobCard.getLotNumber() ) .addValue("purchase_order_id", jobCard.getPurchaseOrderId() ) .addValue("location_site_id", jobCard.getLocationSiteId() ) diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java index 416d044..b0b0535 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java @@ -1,7 +1,6 @@ package com.utopiaindustries.dao.ctp; import com.utopiaindustries.model.ctp.JobCardItem; -import com.utopiaindustries.model.ctp.MasterBundle; import com.utopiaindustries.util.KeyHolderFunctions; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; @@ -11,7 +10,6 @@ import org.springframework.stereotype.Repository; import java.util.ArrayList; import java.util.List; -import java.util.Map; @Repository public class JobCardItemDAO { @@ -28,6 +26,7 @@ public class JobCardItemDAO { private final String SELECT_BY_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", TABLE_NAME ); private final String SELECT_BY_JOB_CARD_AND_ACCOUNT_IDS = String.format( "SELECT * FROM %s WHERE job_card_id = :job_card_id AND account_id IN (:account_ids) AND is_complete = FALSE ", TABLE_NAME ); private final String SELECT_ALL_ACTIVE_ITEM = String.format("SELECT CASE WHEN MIN(is_complete) = TRUE THEN TRUE ELSE FALSE END FROM %s WHERE job_card_id = :job_card_id AND id IN (:id)", TABLE_NAME); + private final String SELECT_BY_JOB_CARD_IDS = String.format( "SELECT * FROM %s WHERE job_card_id IN (:job_card_id)", TABLE_NAME ); public JobCardItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; @@ -131,4 +130,10 @@ public class JobCardItemDAO { Boolean allComplete = namedParameterJdbcTemplate.queryForObject(SELECT_ALL_ACTIVE_ITEM, params, Boolean.class); return Boolean.TRUE.equals(allComplete); } + + public List findByJobCardIds(List ids){ + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("job_card_id", ids); + return namedParameterJdbcTemplate.query( SELECT_BY_JOB_CARD_IDS, params, new JobCardItemRowMapper() ); + } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java index e3f58c3..a0dccfc 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java @@ -22,6 +22,7 @@ public class JobCardItemRowMapper implements RowMapper { jobCardItem.setGsm( rs.getString("gsm" ) ); jobCardItem.setWtPly( rs.getString("wt_ply" ) ); jobCardItem.setPly( rs.getString("ply" ) ); + jobCardItem.setComplete( rs.getBoolean("is_complete" ) ); return jobCardItem; } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardRowMapper.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardRowMapper.java index 2f792c1..5974bc2 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardRowMapper.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardRowMapper.java @@ -23,6 +23,8 @@ public class JobCardRowMapper implements RowMapper { jobCard.setPurchaseOrderId( rs.getString("purchase_order_id") ); jobCard.setLocationSiteId( rs.getLong("location_site_id" ) ); jobCard.setDescription( rs.getString("description" ) ); + jobCard.setPoQuantity( rs.getInt("poQuantity" ) ); + jobCard.setArticleName( rs.getString("articleName" ) ); return jobCard; } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java new file mode 100644 index 0000000..007a50b --- /dev/null +++ b/src/main/java/com/utopiaindustries/model/ctp/CuttingJobCardItemWrapper.java @@ -0,0 +1,150 @@ +package com.utopiaindustries.model.ctp; + +public class CuttingJobCardItemWrapper { + private long jobCardId; + private String poName; + private String sku; + private Long totalCutting; + private String width; + private String length; + private String gsm; + private String wtPly; + private String ply; + private String articleName; + private boolean isComplete; + private String jobCardCode; + private String cuttingOperatorName; + private long cuttingAccountId; + + public long getJobCardId() { + return jobCardId; + } + + public void setJobCardId(long jobCardId) { + this.jobCardId = jobCardId; + } + + public String getPoName() { + return poName; + } + + public void setPoName(String poName) { + this.poName = poName; + } + + public String getSku() { + return sku; + } + + public void setSku(String sku) { + this.sku = sku; + } + + public Long getTotalCutting() { + return totalCutting; + } + + public void setTotalCutting(Long totalCutting) { + this.totalCutting = totalCutting; + } + + public String getWidth() { + return width; + } + + public void setWidth(String width) { + this.width = width; + } + + public String getGsm() { + return gsm; + } + + public void setGsm(String gsm) { + this.gsm = gsm; + } + + public String getWtPly() { + return wtPly; + } + + public void setWtPly(String wtPly) { + this.wtPly = wtPly; + } + + public String getPly() { + return ply; + } + + public void setPly(String ply) { + this.ply = ply; + } + + public String getArticleName() { + return articleName; + } + + public void setArticleName(String articleName) { + this.articleName = articleName; + } + + public boolean isComplete() { + return isComplete; + } + + public void setComplete(boolean complete) { + isComplete = complete; + } + + public String getJobCardCode() { + return jobCardCode; + } + + public void setJobCardCode(String jobCardCode) { + this.jobCardCode = jobCardCode; + } + + public long getCuttingAccountId() { + return cuttingAccountId; + } + + public void setCuttingAccountId(long cuttingAccountId) { + this.cuttingAccountId = cuttingAccountId; + } + + public String getLength() { + return length; + } + + public void setLength(String length) { + this.length = length; + } + + public String getCuttingOperatorName() { + return cuttingOperatorName; + } + + public void setCuttingOperatorName(String cuttingOperatorName) { + this.cuttingOperatorName = cuttingOperatorName; + } + + @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 + '\'' + + ", poName='" + poName + '\'' + + ", jobCardId=" + jobCardId + + '}'; + } +} diff --git a/src/main/java/com/utopiaindustries/model/ctp/JobCard.java b/src/main/java/com/utopiaindustries/model/ctp/JobCard.java index d8a1e74..d3c9271 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/JobCard.java +++ b/src/main/java/com/utopiaindustries/model/ctp/JobCard.java @@ -27,6 +27,8 @@ public class JobCard { private String purchaseOrderId; private long locationSiteId; private String description; + private String articleName; + private int poQuantity; // wrapper private List items; private long toAccountId; @@ -162,6 +164,22 @@ public class JobCard { this.locationTitle = locationTitle; } + public String getArticleName() { + return articleName; + } + + public void setArticleName(String articleName) { + this.articleName = articleName; + } + + public int getPoQuantity() { + return poQuantity; + } + + public void setPoQuantity(int poQuantity) { + this.poQuantity = poQuantity; + } + @Override public String toString() { return "JobCard{" + @@ -174,9 +192,11 @@ public class JobCard { ", inventoryStatus='" + inventoryStatus + '\'' + ", customer='" + customer + '\'' + ", lotNumber='" + lotNumber + '\'' + - ", purchaseOrderId=" + purchaseOrderId + + ", purchaseOrderId='" + purchaseOrderId + '\'' + ", locationSiteId=" + locationSiteId + ", description='" + description + '\'' + + ", articleName='" + articleName + '\'' + + ", poQuantity=" + poQuantity + ", items=" + items + ", toAccountId=" + toAccountId + ", purchaseOrderTitle='" + purchaseOrderTitle + '\'' + diff --git a/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java b/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java index 0c7e2c3..caad229 100644 --- a/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java +++ b/src/main/java/com/utopiaindustries/querybuilder/ctp/SummaryInventoryReportQueryBuilder.java @@ -62,11 +62,33 @@ public class SummaryInventoryReportQueryBuilder { .bracketClose() .bracketClose() .and() - .columnBetween("transaction_leg_date",startDate,endDate) + .columnBetween("transaction_leg_datetime",startDate,endDate) .groupBy("DATE(transaction_leg_datetime), sku, parent_document_type, parent_document_piece_type") .orderBy("transaction_date,", "sku"); return qb.build(); + } + public static String cuttingQueryBuild(long jobCardId, + List account, + String startDate, + String endDate,String type) { + + QueryBuilder qb = new QueryBuilder() + .setTable(TABLE_NAME) + .setColumns("*") + .where() + .columnIn("account_id",account.toArray(new Long[0])) + .and() + .columnEqualToOrGreaterThan("transaction_leg_datetime",startDate) + .and() + .columnEqualToOrLessThan("transaction_leg_datetime",endDate) + .and() + .columnEquals("type",type); + if (jobCardId != 0){ + qb.and() + .columnEquals("job_card_id", jobCardId ); + } + 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 acaa4df..c804ef6 100644 --- a/src/main/java/com/utopiaindustries/service/ReportingService.java +++ b/src/main/java/com/utopiaindustries/service/ReportingService.java @@ -3,6 +3,7 @@ package com.utopiaindustries.service; import com.utopiaindustries.dao.ctp.*; import com.utopiaindustries.model.ctp.*; +import com.utopiaindustries.querybuilder.ctp.SummaryInventoryReportQueryBuilder; import com.utopiaindustries.util.CTPDateTimeFormat; import com.utopiaindustries.util.StringUtils; import org.springframework.stereotype.Service; @@ -21,7 +22,7 @@ import java.util.stream.Collectors; public class ReportingService { private final JobCardItemDAO jobCardItemDAO; - private final CutPieceDAO cutPieceDAO; + private final ProcessDAO processDAO; private final BundleDAO bundleDAO; private final InventoryTransactionLegDAO inventoryTransactionLegDAO; private final InventoryTransactionDAO inventoryTransactionDAO; @@ -32,9 +33,9 @@ public class ReportingService { private final StitchingOfflineItemDAO stitchingOfflineItemDAO; private final InventoryAccountDAO inventoryAccountDAO; - public ReportingService( JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, BundleDAO bundleDAO, InventoryTransactionLegDAO inventoryTransactionLegDAO, InventoryTransactionDAO inventoryTransactionDAO, JobCardDAO jobCardDAO, CryptographyService cryptographyService, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO, InventoryAccountDAO inventoryAccountDAO) { + public ReportingService( JobCardItemDAO jobCardItemDAO, ProcessDAO processDAO, BundleDAO bundleDAO, InventoryTransactionLegDAO inventoryTransactionLegDAO, InventoryTransactionDAO inventoryTransactionDAO, JobCardDAO jobCardDAO, CryptographyService cryptographyService, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO, InventoryAccountDAO inventoryAccountDAO) { this.jobCardItemDAO = jobCardItemDAO; - this.cutPieceDAO = cutPieceDAO; + this.processDAO = processDAO; this.bundleDAO = bundleDAO; this.inventoryTransactionLegDAO = inventoryTransactionLegDAO; this.inventoryTransactionDAO = inventoryTransactionDAO; @@ -442,20 +443,33 @@ public class ReportingService { return barChartData; } - public List getAllPOs() { + public List getAllPOs(String poName) { List pOsDetailsList = new ArrayList<>(); List jobCards = jobCardDAO.findAll() ; - HashMap> filterJobCardsByPos = jobCards.stream() - .collect(Collectors.groupingBy( - JobCard::getPurchaseOrderId, - HashMap::new, - Collectors.toList() - )); + HashMap> filterJobCardsByPos; + if(poName != null && !poName.isEmpty()) { + filterJobCardsByPos = jobCards.stream() + .filter(jobCard -> jobCard.getPurchaseOrderId().equals(poName)) + .collect(Collectors.groupingBy( + JobCard::getPurchaseOrderId, + HashMap::new, + Collectors.toList() + )); + }else { + filterJobCardsByPos = jobCards.stream() + .collect(Collectors.groupingBy( + JobCard::getPurchaseOrderId, + HashMap::new, + Collectors.toList() + )); + } Map jobCardCompleteItems = new HashMap<>(); for (String pos : filterJobCardsByPos.keySet()) { BigDecimal totalProduction = BigDecimal.ZERO; BigDecimal actualProduction = BigDecimal.ZERO; + int poQuantity = 0; + String articleName = ""; Long qaProgressItems = 0L; Long totalFinishItem = 0L; POsDetails pOsDetails = new POsDetails(); @@ -468,7 +482,8 @@ public class ReportingService { actualProduction = actualProduction.add(jobCardItems.stream() .map(item -> Optional.ofNullable(item.getActualProduction()).orElse(BigDecimal.ZERO)) .reduce(BigDecimal.ZERO, BigDecimal::add)); - + poQuantity = jobCard.getPoQuantity(); + articleName = jobCard.getArticleName(); qaProgressItems += Optional.ofNullable(stitchingOfflineItemDAO.CalculateTotalQA(jobCard.getId())).orElse(0L); totalFinishItem += Optional.ofNullable(finishedItemDAO.calculateTotalFinishItem(jobCard.getId())).orElse(0L); @@ -479,16 +494,17 @@ public class ReportingService { } pOsDetails.setPoNumber(pos); - pOsDetails.setPoQuantity(100); + pOsDetails.setArticleTitle(articleName); + pOsDetails.setPoQuantity(poQuantity); pOsDetails.setTotalCutting(actualProduction.intValue()); pOsDetails.setTotalStitching(totalProduction.intValue()); pOsDetails.setTotalEndLineQC(qaProgressItems.intValue()); pOsDetails.setTotalFinishing(totalFinishItem); - pOsDetails.setRemainingCutting(100 - actualProduction.intValue()); - pOsDetails.setRemainingStitching(100 - totalProduction.intValue()); - pOsDetails.setRemainingEndLineQC(100 - qaProgressItems); - pOsDetails.setRemainingFinishing(100 - totalFinishItem); + pOsDetails.setRemainingCutting(poQuantity - actualProduction.intValue()); + pOsDetails.setRemainingStitching(poQuantity - totalProduction.intValue()); + pOsDetails.setRemainingEndLineQC(poQuantity - qaProgressItems); + pOsDetails.setRemainingFinishing(poQuantity - totalFinishItem); pOsDetails.setTotalAGradeItem(jobCardCompleteItems.getOrDefault("A GRADE", 0)); pOsDetails.setTotalBGradeItem(jobCardCompleteItems.getOrDefault("B GRADE", 0)); @@ -525,6 +541,7 @@ public class ReportingService { //stitching day wise Integer stitching = stitchingOfflineItems.size(); + //total qa Integer qa = finishedItems.size(); Map segregateItems = inventoryTransactionLegs.stream() .filter(leg -> inventoryAccounts.stream() @@ -576,6 +593,105 @@ public class ReportingService { return poJobCardItemsProgress; } + public Map getCuttingTableDetails(String jobCardId, String cuttingTableId, String startDate, String endDate) { + Map cuttingDetails = 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", 1L); + List inventoryAccountIds = inventoryAccounts.stream().map(InventoryAccount::getId).collect(Collectors.toList()); + + if (!StringUtils.isNullOrEmpty(jobCardId)) { + jobCardIdTemp = Long.parseLong(jobCardId); + } else if (!StringUtils.isNullOrEmpty(cuttingTableId)) { + inventoryAccountIds = List.of(Long.parseLong(cuttingTableId)); + } + + String query = SummaryInventoryReportQueryBuilder.cuttingQueryBuild(jobCardIdTemp, inventoryAccountIds, startDate1, endDate1, "IN"); + 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()) { + List jobCardIds = entry.getValue(); + if (!jobCardIds.isEmpty()) { + List jobCardItems = jobCardItemDAO.findByJobCardIds(jobCardIds); + int totalProduction = jobCardItems.stream() + .filter(item -> item.getActualProduction() != null) + .mapToInt(item -> item.getActualProduction().intValue()) + .sum(); + dateWiseProduction.put(entry.getKey().format(formatter), totalProduction); + } + } + + List distinctJobCardIds = inventoryTransactionLegs.stream() + .map(InventoryTransactionLeg::getJobCardId) + .filter(id -> id != 0) + .distinct() + .collect(Collectors.toList()); + + Map> jobCardItemsCuttingDetailsMap = 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); + Bundle bundle = bundleDAO.findByCardId(jobCardIdEntry).stream().findFirst().orElse(new Bundle()); + + List jobCardItems = jobCardItemDAO.findByCardId(jobCardIdEntry); + + List wrappers = jobCardItems.stream().map(item -> { + CuttingJobCardItemWrapper wrapper = new CuttingJobCardItemWrapper(); + wrapper.setArticleName(jobCard.getArticleName()); + wrapper.setJobCardCode(jobCard.getCode()); + wrapper.setGsm(item.getGsm()); + wrapper.setPly(item.getPly()); + wrapper.setSku(item.getSku()); + wrapper.setTotalCutting(item.getActualProduction().longValue()); + wrapper.setWidth(item.getWidth()); + wrapper.setWtPly(item.getWtPly()); + wrapper.setComplete(item.isComplete()); + wrapper.setPoName(jobCard.getPurchaseOrderId()); + wrapper.setCuttingOperatorName(bundle.getCreatedBy()); + wrapper.setJobCardId(item.getJobCardId()); + wrapper.setLength(item.getLength()); + wrapper.setCuttingAccountId(accountId); + return wrapper; + }).collect(Collectors.toList()); + + jobCardItemsCuttingDetailsMap.computeIfAbsent(accountId, k -> new ArrayList<>()).addAll(wrappers); + } + + cuttingDetails.put("Date Wise Cutting", dateWiseProduction); + cuttingDetails.put("accountWiseCutting", jobCardItemsCuttingDetailsMap); + cuttingDetails.put("cuttingAccount", inventoryAccounts); + return cuttingDetails; + } + + private StringBuilder generateTime(LocalDateTime startDate, LocalDateTime endDate){ StringBuilder totalTime = new StringBuilder(); if(startDate != null && endDate != null){ diff --git a/src/main/resources/static/js/charts.js b/src/main/resources/static/js/charts.js index c9887e2..13cc674 100644 --- a/src/main/resources/static/js/charts.js +++ b/src/main/resources/static/js/charts.js @@ -137,60 +137,138 @@ 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 + }] + }); + } + + initializeGauges(); function initializeGauges() { - const gaugeDivs2 = document.querySelectorAll('.gauge-chart2'); - gaugeDivs2.forEach(function (div) { - const progress = div.getAttribute('data-progress'); - const color = div.getAttribute('data-color'); - const title = div.getAttribute('data-title'); - const height = div.getAttribute('data-height'); - const width = div.getAttribute('data-width'); - const fontSize = div.getAttribute('data-fontSize'); - const fontColor = div.getAttribute('data-fontColor'); - const total = div.getAttribute('data-totalProduction'); - const actual = div.getAttribute('data-actualProduction'); - const divId = div.id; - console.log(actual) - createGaugeChart(parseInt(progress), color, divId, title, height, width, fontSize, -20, 4, fontColor, total, actual); - }); - const gaugeDivs = document.querySelectorAll('.gauge-chart'); - gaugeDivs.forEach(function (div) { - const progress = div.getAttribute('data-progress'); - const color = div.getAttribute('data-color'); - const title = div.getAttribute('data-title'); - const height = div.getAttribute('data-height'); - const width = div.getAttribute('data-width'); - const fontSize = div.getAttribute('data-fontSize'); - const fontColor = div.getAttribute('data-fontColor'); - const total = div.getAttribute('data-totalProduction'); - const actual = div.getAttribute('data-actualProduction'); - const aGrade = div.getAttribute('data-aGrade'); - const bGrade = div.getAttribute('data-bGrade'); - const cGrade = div.getAttribute('data-cGrade'); - const divId = div.id; - createGaugeChart(parseInt(progress), color, divId, title, height, width, fontSize, -15, 2, fontColor, total, actual, aGrade, bGrade, cGrade); - }); - const barChart = document.querySelectorAll('.barChart'); - barChart.forEach(function (div) { - const title = div.getAttribute('data-title'); - const height = div.getAttribute('data-height'); - const width = div.getAttribute('data-width'); - const fontSize = div.getAttribute('data-fontSize'); - const maxValue = Number(div.getAttribute('data-totalProduction')); - const aHeading = 'Cutting'; - const aData = JSON.parse(div.getAttribute('data-cutting')); - const bHeading='Stitching'; - const bData =JSON.parse(div.getAttribute('data-stitching')); - const cHeading='End Line Quality Checking'; - const cData =JSON.parse(div.getAttribute('data-quality')); - const dHeading="Finish Items"; - const dData =JSON.parse(div.getAttribute('data-finishing')); - const dates = div.getAttribute('data-dates'); - const datesArray = dates.split(','); - const divId = div.id; - createBarChart( divId, height, width, title,aHeading,aData,bHeading,bData,cHeading,cData,dHeading,dData,datesArray,fontSize,maxValue); + const gaugeDivs2 = document.querySelectorAll('.gauge-chart2'); + gaugeDivs2.forEach(function (div) { + const progress = div.getAttribute('data-progress'); + const color = div.getAttribute('data-color'); + const title = div.getAttribute('data-title'); + const height = div.getAttribute('data-height'); + const width = div.getAttribute('data-width'); + const fontSize = div.getAttribute('data-fontSize'); + const fontColor = div.getAttribute('data-fontColor'); + const total = div.getAttribute('data-totalProduction'); + const actual = div.getAttribute('data-actualProduction'); + const divId = div.id; + console.log(actual) + createGaugeChart(parseInt(progress), color, divId, title, height, width, fontSize, -20, 4, fontColor, total, actual); + }); + + const gaugeDivs = document.querySelectorAll('.gauge-chart'); + gaugeDivs.forEach(function (div) { + const progress = div.getAttribute('data-progress'); + const color = div.getAttribute('data-color'); + const title = div.getAttribute('data-title'); + const height = div.getAttribute('data-height'); + const width = div.getAttribute('data-width'); + const fontSize = div.getAttribute('data-fontSize'); + const fontColor = div.getAttribute('data-fontColor'); + const total = div.getAttribute('data-totalProduction'); + const actual = div.getAttribute('data-actualProduction'); + const aGrade = div.getAttribute('data-aGrade'); + const bGrade = div.getAttribute('data-bGrade'); + const cGrade = div.getAttribute('data-cGrade'); + const divId = div.id; + createGaugeChart(parseInt(progress), color, divId, title, height, width, fontSize, -15, 2, fontColor, total, actual, aGrade, bGrade, cGrade); + + }); + + const barChart = document.querySelectorAll('.barChart'); + barChart.forEach(function (div) { + const title = div.getAttribute('data-title'); + const height = div.getAttribute('data-height'); + const width = div.getAttribute('data-width'); + const fontSize = div.getAttribute('data-fontSize'); + const maxValue = Number(div.getAttribute('data-totalProduction')); + const aHeading = 'Cutting'; + const aData = JSON.parse(div.getAttribute('data-cutting')); + const bHeading='Stitching'; + const bData =JSON.parse(div.getAttribute('data-stitching')); + const cHeading='End Line Quality Checking'; + const cData =JSON.parse(div.getAttribute('data-quality')); + const dHeading="Finish Items"; + const dData =JSON.parse(div.getAttribute('data-finishing')); + const dates = div.getAttribute('data-dates'); + const datesArray = dates.split(','); + const divId = div.id; + createBarChart( divId, height, width, title, aHeading, aData, bHeading, bData, cHeading, cData, dHeading, dData, datesArray, fontSize, maxValue); + }); + + const cuttingBarChart = document.querySelectorAll('.cuttingBarChart'); + cuttingBarChart.forEach(function (div) { + const title = div.getAttribute('data-title'); + const height = div.getAttribute('data-height'); + const width = div.getAttribute('data-width'); + const fontSize = div.getAttribute('data-fontSize'); + const maxValue = Number(div.getAttribute('data-totalProduction')); + const Heading = div.getAttribute('data-barHeading'); + const Data = JSON.parse(div.getAttribute('data-barData')); + const dates = div.getAttribute('data-dates'); + const datesArray = dates.split(','); + const divId = div.id; + createSingleBarChart( divId, height, width, title, Heading, Data, datesArray, fontSize, maxValue); }); } }); diff --git a/src/main/resources/templates/_fragments.html b/src/main/resources/templates/_fragments.html index dc808c2..4635a1d 100644 --- a/src/main/resources/templates/_fragments.html +++ b/src/main/resources/templates/_fragments.html @@ -140,6 +140,10 @@ th:classappend="${#strings.startsWith(#httpServletRequest.getRequestURI(), '/ctp/reporting/job-card-report') ? 'active' : ''}"> Job Card Report +