diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index d9f4e72..3d7f0db 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -21,6 +21,11 @@
+
+
+
+
+
diff --git a/pom.xml b/pom.xml
index 8c45d85..a214b33 100644
--- a/pom.xml
+++ b/pom.xml
@@ -389,7 +389,7 @@
-Xms1024m
-Xmx8g
-
+ org.apache.maven.pluginsmaven-compiler-plugin88
diff --git a/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java b/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java
index 78a3d7a..1775827 100644
--- a/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java
+++ b/src/main/java/com/utopiaindustries/model/ctp/BarcodeStickerSize.java
@@ -6,7 +6,8 @@ public enum BarcodeStickerSize {
SIZE_2_X_3( 3 * 72, 2 * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
SIZE_4_X_4( 4 * 72, 4 * 72, 8, 8, 8, 8, 200, 100, 250, 250, 14, 9, 7),
SIZE_1_75_X_3_5( 3.5f * 72, 1.75f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
- SIZE_4_X_7( 7f * 72, 4f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7);
+ SIZE_4_X_7( 7f * 72, 4f * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7),
+ SIZE_1_X_2( 94f, 49f , 20, 10, 48, 6, 42, 42, 125, 125, 4, 9, 7);
private final float width;
diff --git a/src/main/java/com/utopiaindustries/model/ctp/InventoryArtifact.java b/src/main/java/com/utopiaindustries/model/ctp/InventoryArtifact.java
index 8c4b981..9c4e231 100644
--- a/src/main/java/com/utopiaindustries/model/ctp/InventoryArtifact.java
+++ b/src/main/java/com/utopiaindustries/model/ctp/InventoryArtifact.java
@@ -4,6 +4,7 @@ public interface InventoryArtifact {
long getId();
long getItemId();
+ long getJobCardId();
String getSku();
String getType();
String getBarcode();
diff --git a/src/main/java/com/utopiaindustries/service/BarcodeService.java b/src/main/java/com/utopiaindustries/service/BarcodeService.java
index 27a52a0..947507d 100644
--- a/src/main/java/com/utopiaindustries/service/BarcodeService.java
+++ b/src/main/java/com/utopiaindustries/service/BarcodeService.java
@@ -1,10 +1,7 @@
package com.utopiaindustries.service;
import com.google.zxing.BarcodeFormat;
-import com.utopiaindustries.dao.ctp.BundleDAO;
-import com.utopiaindustries.dao.ctp.FinishedItemDAO;
-import com.utopiaindustries.dao.ctp.MasterBundleDAO;
-import com.utopiaindustries.dao.ctp.StitchingOfflineItemDAO;
+import com.utopiaindustries.dao.ctp.*;
import com.utopiaindustries.model.ctp.*;
import com.utopiaindustries.util.BarcodeUtils;
import com.utopiaindustries.util.StringUtils;
@@ -19,11 +16,23 @@ import org.springframework.stereotype.Service;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.Font;
+import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
-import java.io.ByteArrayInputStream;
+import java.io.*;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
+import com.google.zxing.EncodeHintType;
+import com.google.zxing.qrcode.QRCodeWriter;
+import com.google.zxing.WriterException;
+import com.google.zxing.common.BitMatrix;
+
+import java.io.ByteArrayInputStream;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.stream.Collectors;
@Service
public class BarcodeService {
@@ -35,12 +44,14 @@ public class BarcodeService {
private int port;
private final BundleDAO bundleDAO;
+ private final JobCardDAO jobCardDAO;
private final MasterBundleDAO masterBundleDAO;
private final FinishedItemDAO finishedItemDAO;
private final StitchingOfflineItemDAO stitchingOfflineItemDAO;
- public BarcodeService(BundleDAO bundleDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) {
+ public BarcodeService(BundleDAO bundleDAO, JobCardDAO jobCardDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) {
this.bundleDAO = bundleDAO;
+ this.jobCardDAO = jobCardDAO;
this.masterBundleDAO = masterBundleDAO;
this.finishedItemDAO = finishedItemDAO;
this.stitchingOfflineItemDAO = stitchingOfflineItemDAO;
@@ -56,14 +67,16 @@ public class BarcodeService {
List extends InventoryArtifact> list = new ArrayList<>();
if (StringUtils.compare(artifactType, Bundle.class.getSimpleName())) {
list = bundleDAO.findByIds(ids);
+ getBarcodeImages(list, stickerSize, artifactType);
} else if (StringUtils.compare(artifactType, MasterBundle.class.getSimpleName())) {
list = masterBundleDAO.findByIds(ids);
+ getBarcodeImages(list, stickerSize, artifactType);
} else if (StringUtils.compare(artifactType, FinishedItem.class.getSimpleName())) {
+ String sizeForStitchItem = BarcodeStickerSize.SIZE_1_X_2.name();
+ BarcodeStickerSize stickerSizeForStitchItem = BarcodeStickerSize.getSize(sizeForStitchItem);
list = stitchingOfflineItemDAO.findByIds(ids);
+ getBarcodeImagesForStitchItems(list, stickerSizeForStitchItem, artifactType);
}
-
- getBarcodeImages(list, stickerSize, artifactType);
-
}
public void getBarcodeImages(List extends InventoryArtifact> artifacts,
@@ -129,6 +142,138 @@ public class BarcodeService {
}
}
+ public void getBarcodeImagesForStitchItems(List extends InventoryArtifact> artifacts,
+ BarcodeStickerSize stickerSize,
+ String artifactType) throws Exception {
+
+ for (InventoryArtifact artifact : artifacts) {
+ JobCard jobCard = jobCardDAO.find(artifact.getJobCardId());
+ List bundles = bundleDAO.findByItemIdAndCardId( artifact.getItemId( ), jobCard.getId( ));
+ String concatenatedIds = bundles.stream()
+ .map(bundle -> String.valueOf(bundle.getId()))
+ .collect(Collectors.joining("\\"));
+ // Set Portrait Mode Dimensions
+ int stickerWidth = (int) stickerSize.getWidth();
+ int stickerHeight = (int) stickerSize.getHeight();
+
+ BufferedImage stickerImage = new BufferedImage(stickerWidth * 2, stickerHeight * 2, BufferedImage.TYPE_INT_ARGB);
+ Graphics2D g2d = stickerImage.createGraphics();
+ g2d.scale(2, 2);
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
+
+ g2d.setColor(Color.WHITE);
+ g2d.fillRect(0, 0, stickerWidth, stickerHeight);
+
+ // Draw Stitch Line (Dotted Line at the Top)
+ String stitchLine = "|";
+ Font fontLine = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()-2);
+ g2d.setFont(fontLine);
+ FontMetrics fontMetricsLine = g2d.getFontMetrics();
+ int textWidthLine = fontMetricsLine.stringWidth(stitchLine);
+ int centerXLine = stickerSize.getMarginLeft();
+ g2d.setColor(Color.BLACK);
+ for(int i=0;i<16;i++){
+ g2d.drawString(stitchLine, centerXLine,5+(i*3));
+ }
+
+
+ // Draw ID Below Stitch Line
+ String id = String.valueOf(artifact.getId());
+ g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()));
+ FontMetrics fontMetricsId = g2d.getFontMetrics();
+ int textHeightId = fontMetricsId.getHeight();
+ int centerXID = stickerSize.getMarginLeft()+7;
+ int centerYID = (stickerHeight / 2) + (textHeightId / 4);
+ AffineTransform originalTransform = g2d.getTransform();
+ g2d.rotate(Math.toRadians(-90), centerXID, centerYID);
+ g2d.drawString(id, centerXID, centerYID);
+ g2d.setTransform(originalTransform);
+
+ // Draw QR Code Below the ID
+ byte[] imgBytes = generateQRCodeImageByteArray(artifact.getBarcode(), stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
+ BufferedImage qrCodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
+
+ int centerXQR = stickerSize.getMarginLeft()-12;
+ int centerYQR = (stickerHeight / 2) + (textHeightId / 2)+1;
+ AffineTransform originalTransformQR = g2d.getTransform();
+ g2d.rotate(Math.toRadians(-90), centerXID, centerYID);
+ g2d.drawImage(qrCodeImage, centerXQR, centerYQR, null);
+ g2d.setTransform(originalTransformQR);
+
+ // Prepare Text Lines Below QR Code
+ String sku = artifact.getSku();
+ String jobCardCode = jobCard.getCode();
+ String combinedText = sku + " \\" + jobCardCode + concatenatedIds;
+
+ int maxLength = 16; // Max characters per line
+ List lines = new ArrayList<>();
+
+ for (int i = 0; i < 3; i++) {
+ int start = i * maxLength;
+ if (start < combinedText.length()) {
+ String part = combinedText.substring(start, Math.min(start + maxLength, combinedText.length())).trim();
+ lines.add(part);
+ }
+ }
+ g2d.rotate(Math.toRadians(-90), stickerWidth / 2, stickerHeight / 2);
+
+// Draw Rotated Text Below QR Code
+ g2d.setColor(Color.BLACK);
+ g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()));
+ FontMetrics fontMetrics = g2d.getFontMetrics();
+ int lineHeight = fontMetrics.getHeight();
+ int centerXSKU = stickerSize.getMarginLeft()+4;
+ int centerYSKU = (stickerHeight / 2) + (textHeightId / 4)+20;
+
+ AffineTransform originalTransformSKu = g2d.getTransform();
+ g2d.rotate(Math.toRadians(-0.1), centerXSKU, centerYSKU);
+ for (int i = 0; i < lines.size(); i++) {
+ int lineWidth = fontMetrics.stringWidth(lines.get(i));
+ g2d.drawString(lines.get(i), (stickerWidth - lineWidth) / 2, centerYSKU + (i * lineHeight));
+ }
+
+ g2d.setTransform(originalTransformSKu);
+
+ g2d.dispose();
+
+ // Save Image
+ Path path = FileSystems.getDefault().getPath("./src/main/resources/static/sample_qr.png");
+ File outputFile = path.toFile();
+ ImageIO.write(stickerImage, "PNG", outputFile);
+ }
+ }
+
+
+ public byte[] generateQRCodeImageByteArray(String data, int width, int height) {
+ try {
+ QRCodeWriter qrCodeWriter = new QRCodeWriter();
+
+ // QR Code generation settings
+ Map hintMap = new HashMap<>();
+ hintMap.put(EncodeHintType.MARGIN, 1); // Optional: control margin size
+
+ // Generate QR code matrix
+ BitMatrix bitMatrix = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, width, height, hintMap);
+
+ // Convert BitMatrix to BufferedImage
+ BufferedImage qrImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
+ qrImage.createGraphics().fillRect(0, 0, width, height);
+
+ for (int x = 0; x < width; x++) {
+ for (int y = 0; y < height; y++) {
+ qrImage.setRGB(x, y, bitMatrix.get(x, y) ? 0x000000 : 0xFFFFFF); // Black and white
+ }
+ }
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ImageIO.write(qrImage, "PNG", baos);
+ return baos.toByteArray();
+ } catch (WriterException | IOException e) {
+ e.printStackTrace();
+ return new byte[0];
+ }
+ }
+
public void printLabel( BufferedImage bufferedImage ) throws Exception {
Connection connection = new TcpConnection( ipAddress, port );
connection.open();
diff --git a/src/main/resources/application.yaml b/src/main/resources/application.yaml
index 400eb73..e97f1a6 100644
--- a/src/main/resources/application.yaml
+++ b/src/main/resources/application.yaml
@@ -1,7 +1,7 @@
application:
title: Cut To Pack Service
version: v1.0
- name: application-dev
+ name: application-prod
spring:
profiles: