From 6b722b196550abc6c99e50063ff84c39a2db3520 Mon Sep 17 00:00:00 2001 From: "usama.jameel" Date: Thu, 22 May 2025 15:02:45 +0500 Subject: [PATCH] add formula of efficiency and shift target --- .../dao/ctp/InventoryAccountDAO.java | 14 +- .../dao/ctp/InventoryAccountRowMapper.java | 5 +- .../model/ctp/InventoryAccount.java | 34 ++- .../service/DashboardService.java | 66 +++-- .../_inventory-account-fragment.html | 238 +++++++++--------- src/main/resources/templates/dashboard.html | 3 +- 6 files changed, 209 insertions(+), 151 deletions(-) diff --git a/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java index fe10062..95b0aee 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java @@ -21,8 +21,8 @@ public class InventoryAccountDAO { private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY title DESC", 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, title, parent_entity_type, parent_entity_id, active, created_by, created_at, location_site_id, notes, is_packaging, article_name, daily_target, total_machines, hourly_target) " + - "VALUES (:id, :title, :parent_entity_type, :parent_entity_id, :active, :created_by, :created_at, :location_site_id, :notes, :is_packaging, :article_name, :daily_target, :total_machines, :hourly_target) " + + "INSERT INTO %s (id, title, parent_entity_type, parent_entity_id, active, created_by, created_at, location_site_id, notes, is_packaging, article_name, shift_minutes, total_machines, efficiency, sam) " + + "VALUES (:id, :title, :parent_entity_type, :parent_entity_id, :active, :created_by, :created_at, :location_site_id, :notes, :is_packaging, :article_name, :shift_minutes, :total_machines, :efficiency, :sam) " + "ON DUPLICATE KEY UPDATE " + "title = VALUES(title), " + "parent_entity_type = VALUES(parent_entity_type), " + @@ -34,8 +34,9 @@ public class InventoryAccountDAO { "notes = VALUES(notes), " + "is_packaging = VALUES(is_packaging), " + "article_name = VALUES(article_name), " + - "daily_target = VALUES(daily_target), " + - "hourly_target = VALUES(hourly_target), " + + "shift_minutes = VALUES(shift_minutes), " + + "efficiency = VALUES(efficiency), " + + "sam = VALUES(sam), " + "total_machines = VALUES(total_machines)", TABLE_NAME ); @@ -65,8 +66,9 @@ public class InventoryAccountDAO { .addValue( "notes", inventoryAccount.getNotes() ) .addValue( "article_name", inventoryAccount.getArticleName() ) .addValue( "total_machines", inventoryAccount.getTotalMachines() ) - .addValue( "daily_target", inventoryAccount.getDailyTarget() ) - .addValue( "hourly_target", inventoryAccount.getHourlyTarget() ) + .addValue( "shift_minutes", inventoryAccount.getShiftMinutes() ) + .addValue( "efficiency", inventoryAccount.getEfficiency() ) + .addValue( "sam", inventoryAccount.getSam() ) .addValue("is_packaging", inventoryAccount.getIsPackaging() ); return params; } diff --git a/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountRowMapper.java b/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountRowMapper.java index 12930e5..d015aea 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountRowMapper.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountRowMapper.java @@ -21,9 +21,10 @@ public class InventoryAccountRowMapper implements RowMapper { inventoryAccount.setLocationSiteId( rs.getInt( "location_site_id" ) ); inventoryAccount.setNotes( rs.getString( "notes" ) ); inventoryAccount.setArticleName( rs.getString( "article_name" ) ); - inventoryAccount.setDailyTarget( rs.getLong( "daily_target" ) ); + inventoryAccount.setShiftMinutes( rs.getLong( "shift_minutes" ) ); inventoryAccount.setTotalMachines( rs.getLong( "total_machines" ) ); - inventoryAccount.setHourlyTarget( rs.getLong( "hourly_target" ) ); + inventoryAccount.setEfficiency( rs.getBigDecimal( "efficiency" ) ); + inventoryAccount.setSam( rs.getBigDecimal( "sam" ) ); inventoryAccount.setIsPackaging( rs.getBoolean("is_packaging" ) ); return inventoryAccount; } diff --git a/src/main/java/com/utopiaindustries/model/ctp/InventoryAccount.java b/src/main/java/com/utopiaindustries/model/ctp/InventoryAccount.java index 7f13cb7..331f528 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/InventoryAccount.java +++ b/src/main/java/com/utopiaindustries/model/ctp/InventoryAccount.java @@ -1,5 +1,6 @@ package com.utopiaindustries.model.ctp; +import java.math.BigDecimal; import java.time.LocalDateTime; public class InventoryAccount { @@ -15,9 +16,10 @@ public class InventoryAccount { private String notes; private Boolean isPackaging; private String articleName; - private long dailyTarget; + private long shiftMinutes; private long totalMachines; - private long hourlyTarget; + private BigDecimal efficiency; + private BigDecimal sam; //wrapper private String locationTitle; @@ -118,12 +120,12 @@ public class InventoryAccount { this.articleName = articleName; } - public long getDailyTarget() { - return dailyTarget; + public long getShiftMinutes() { + return shiftMinutes; } - public void setDailyTarget(long dailyTarget) { - this.dailyTarget = dailyTarget; + public void setShiftMinutes(long shiftMinutes) { + this.shiftMinutes = shiftMinutes; } public long getTotalMachines() { @@ -134,12 +136,20 @@ public class InventoryAccount { this.totalMachines = totalMachines; } - public long getHourlyTarget() { - return hourlyTarget; + public BigDecimal getEfficiency() { + return efficiency; } - public void setHourlyTarget(long hourlyTarget) { - this.hourlyTarget = hourlyTarget; + public void setEfficiency(BigDecimal efficiency) { + this.efficiency = efficiency; + } + + public BigDecimal getSam() { + return sam; + } + + public void setSam(BigDecimal sam) { + this.sam = sam; } @Override @@ -156,9 +166,9 @@ public class InventoryAccount { ", notes='" + notes + '\'' + ", isPackaging=" + isPackaging + ", articleName='" + articleName + '\'' + - ", dailyTarget=" + dailyTarget + + ", shiftMinutes=" + shiftMinutes + ", totalMachines=" + totalMachines + - ", hourlyTarget=" + hourlyTarget + + ", efficiency=" + efficiency + ", locationTitle='" + locationTitle + '\'' + '}'; } diff --git a/src/main/java/com/utopiaindustries/service/DashboardService.java b/src/main/java/com/utopiaindustries/service/DashboardService.java index a497eb4..94b61a2 100644 --- a/src/main/java/com/utopiaindustries/service/DashboardService.java +++ b/src/main/java/com/utopiaindustries/service/DashboardService.java @@ -4,7 +4,11 @@ import com.utopiaindustries.dao.ctp.*; import com.utopiaindustries.model.ctp.*; import org.springframework.stereotype.Service; +import java.math.BigDecimal; +import java.math.RoundingMode; +import java.time.Duration; import java.time.LocalDateTime; +import java.time.LocalTime; import java.time.format.DateTimeFormatter; import java.util.*; import java.util.stream.Collectors; @@ -37,7 +41,9 @@ public class DashboardService { String finishingAccount = "FINISHING ACCOUNT " + lineNo; String packagingAccount = "A GRADE ACCOUNT " + lineNo; - String startDate1 = LocalDateTime.now().withHour(0).withMinute(0).withSecond(1).format(formatter); + LocalDateTime today = LocalDateTime.now().withHour(0).withMinute(0).withSecond(1); + + String startDate1 = today.format(formatter); String endDate1 = LocalDateTime.now().withHour(23).withMinute(59).withSecond(59).format(formatter); String startDateWithHour = LocalDateTime.now().minusHours(1).format(formatter); String endDateWithHour = LocalDateTime.now().format(formatter); @@ -65,7 +71,7 @@ public class DashboardService { List packagingItemIDs = inventoryTransactionLegDAO.findRemainingByParentTypeAndAccountID("PACKAGING", inventoryAccountMap.get(packagingAccount)); Long approvedStitchingOfflineItems = 0L; - Long qcReject = 0L; + long qcReject = 0L; if (stitchingItemIds != null && !stitchingItemIds.isEmpty()) { approvedStitchingOfflineItems = stitchingOfflineItemDAO.findByQCOperationDateAndApproved(startDate1, endDate1, "APPROVED"); qcReject = stitchingOfflineItemDAO.findByQCOperationDateAndIds(null, endDate1, "REJECT", stitchingItemIds); @@ -87,27 +93,35 @@ public class DashboardService { Long packagingItems = 0L; - Long packagingItemsHourly = 0L; if (packagingItemIDs != null && !packagingItemIDs.isEmpty()) { packagingItems = packagingItemsDAO.findByDateAndIds(startDate1, endDate1, packagingItemIDs); - packagingItemsHourly = packagingItemsDAO.findByDateAndIds(startDateWithHour, endDateWithHour, packagingItemIDs); } + LocalDateTime statTime = LocalDateTime.now().withHour(9).withMinute(0).withSecond(0).withNano(0); + LocalDateTime endTime = statTime.plusMinutes(inventoryAccount.getShiftMinutes()); + + long minutesPassed = 0; + + if (statTime.isBefore(LocalDateTime.now()) && LocalDateTime.now().isBefore(endTime)) { + minutesPassed = Duration.between(statTime, LocalDateTime.now()).toMinutes(); + } + + long shiftTargetMinutesWise = getTargetShiftWiseOrHourlyWise(Math.max(0, minutesPassed), inventoryAccount); + float efficiency; + if (shiftTargetMinutesWise == 0) { + efficiency = 0f; + } else { + efficiency = approvedStitchingOfflineItems + (float) qcReject / shiftTargetMinutesWise; + } progress.put("Stitching", (float) approvedStitchingOfflineItems + qcReject); progress.put("totalWips", (float) stitchingItemIds.size() - qcReject); progress.put("Alteration", (float) qcReject); - progress.put("finishing", (float) approved + operationNotPerformed); progress.put("ALTER", (float) alterationPieceFinish); progress.put("Reject", (float) rejectFinishedItem); progress.put("wash", (float) washFinishedItem); progress.put("packaging", (float) packagingItems); - - progress.put("Shift Achieved", (float) packagingItems); - progress.put("Hourly Achieved", Float.valueOf(packagingItemsHourly)); - progress.put("Efficiency", (float) packagingItems / inventoryAccount.getDailyTarget() * 100); - - + progress.put("Efficiency",efficiency); return progress; } @@ -117,15 +131,37 @@ public class DashboardService { InventoryAccount inventoryAccount = inventoryAccounts.stream() .filter(e -> cuttingAccount.equals(e.getTitle())).findFirst().orElse(new InventoryAccount()); + int shiftTarget = getTargetShiftWiseOrHourlyWise(inventoryAccount.getShiftMinutes(), inventoryAccount); + int shiftHourlyTarget = getTargetShiftWiseOrHourlyWise(60, inventoryAccount); + HashMap details = new HashMap<>(); - List jobCards = jobCardDAO.findAll(); - details.put("Shift Target", inventoryAccount.getDailyTarget() + " Pcs"); + details.put("Shift Target", shiftTarget + " Pcs"); details.put("articleName", inventoryAccount.getArticleName()); - details.put("Hourly Target", inventoryAccount.getHourlyTarget() + " Pcs"); - details.put("Total Induction", String.valueOf(jobCards.size())); + details.put("Hourly Target", shiftHourlyTarget + " Pcs"); details.put("Total Machine", String.valueOf(inventoryAccount.getTotalMachines())); details.put("Total Worker", String.valueOf(30)); details.put("line", "Line " + lineNo); return details; } + + //formula for calculating targets --> machine * shiftTime * Efficiency / SAM + private int getTargetShiftWiseOrHourlyWise(long minutes, InventoryAccount inventoryAccount) { + if (inventoryAccount == null || + inventoryAccount.getTotalMachines() == 0 || + inventoryAccount.getEfficiency() == null || + inventoryAccount.getSam() == null) { + return 0; + } + BigDecimal totalMachines = BigDecimal.valueOf(inventoryAccount.getTotalMachines()); + BigDecimal efficiency = inventoryAccount.getEfficiency(); + BigDecimal sam = inventoryAccount.getSam(); + BigDecimal totalShiftProductiveTime = totalMachines + .multiply(BigDecimal.valueOf(minutes)) + .multiply(efficiency); + if (sam.longValue() != 0) { + return totalShiftProductiveTime.divide(sam, 0, RoundingMode.HALF_UP).intValueExact(); + } + return 0; + } + } diff --git a/src/main/resources/templates/_inventory-account-fragment.html b/src/main/resources/templates/_inventory-account-fragment.html index 108db87..e1f81cd 100644 --- a/src/main/resources/templates/_inventory-account-fragment.html +++ b/src/main/resources/templates/_inventory-account-fragment.html @@ -1,122 +1,132 @@ - - -
- -
-
-
- - - -
-
Account
-
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
- - -
-
+ + +
+ +
+
+ + + + +
+
Account
+
+
+ +
-
-
Misc
-
-
- - -
-
- - -
-
- - -
-
-
-
- - -
-
- - -
-
- -
- -
-
-
- -
- -
-
-
+
+ +
-
- - Cancel +
+ +
- +
+ + +
+
+ +
+
+ + +
+
+ + +
+
-
+
+
Misc
+
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+ + +
+
+ +
+ +
+
+
+ +
+ +
+
+
+
+
+ + Cancel +
+
- - +
+
+ + \ No newline at end of file diff --git a/src/main/resources/templates/dashboard.html b/src/main/resources/templates/dashboard.html index 35075f4..ab2b429 100644 --- a/src/main/resources/templates/dashboard.html +++ b/src/main/resources/templates/dashboard.html @@ -87,7 +87,7 @@

0%

+ th:text="${#numbers.formatDecimal(phases.get('Efficiency'), 1, 2) + ' %'}">0%

Efficiency

@@ -100,7 +100,6 @@ -