add_QRCode #8

Merged
saif.haq merged 6 commits from add_QRCode into main 2025-02-27 05:06:04 +00:00
42 changed files with 1021 additions and 212 deletions

View File

@ -21,6 +21,11 @@
<option name="name" value="In project repo" />
<option name="url" value="file:///D:\Projects\uind-cut-to-pack\cut-to-pack/libs" />
</remote-repository>
<remote-repository>
<option name="id" value="in-project" />
<option name="name" value="In project repo" />
<option name="url" value="file:///C:\Users\USF\Project\Cut-to-pack\cut-to-pack-service/libs" />
</remote-repository>
<remote-repository>
<option name="id" value="in-project" />
<option name="name" value="In project repo" />

View File

@ -55,6 +55,12 @@
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.30</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId>
@ -389,7 +395,7 @@
<jvmArguments>-Xms1024m</jvmArguments>
<jvmArguments>-Xmx8g</jvmArguments>
</configuration>
</plugin>
</plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-compiler-plugin</artifactId><configuration><source>8</source><target>8</target></configuration></plugin>
</plugins>
</build>
</project>

View File

@ -1,11 +1,9 @@
package com.utopiaindustries.controller;
import com.utopiaindustries.auth.StitchingRole;
import com.utopiaindustries.model.ctp.JobCard;
import com.utopiaindustries.model.ctp.StitchingOfflineItem;
import com.utopiaindustries.model.ctp.*;
import com.utopiaindustries.service.*;
import com.utopiaindustries.util.StringUtils;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
@ -111,17 +109,17 @@ public class StitchingController {
@GetMapping( "/create-stitching-items")
public String createFinishItems( Model model ){
model.addAttribute("accounts" , inventoryAccountService.findInventoryAccounts( 2L ) );
model.addAttribute("jobCard", jobCardService.createNewJobCard() );
return "/stitching/stitching-item-form";
model.addAttribute("bundleWrapper", new BundleWrapper() );
return "/stitching/stitching-item-form";
}
@PostMapping( "/create-stitching-items" )
public String createStitchedOfflineItems( @ModelAttribute JobCard jobCard,
public String createStitchedOfflineItems( @ModelAttribute BundleWrapper bundleWrapper,
RedirectAttributes redirectAttributes,
Model model ){
try {
inventoryService.createStitchingOfflineItemsFromJobCard( jobCard );
redirectAttributes.addFlashAttribute("success", "Finished Item Created Successfully");
inventoryService.createStitchingOfflineItemsFromJobCard( bundleWrapper );
redirectAttributes.addFlashAttribute("success", "Stitch Items Created Successfully");
} catch ( Exception exception ){
exception.printStackTrace();
redirectAttributes.addFlashAttribute( "error", exception.getMessage() );

View File

@ -21,13 +21,14 @@ public class BundleDAO {
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 ORDER BY id 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, item_id, sku, wrap_quantity, barcode, type, created_by, created_at, job_card_id, master_bundle_id) VALUES (:id, :item_id, :sku, :wrap_quantity, :barcode, :type, :created_by, :created_at, :job_card_id, :master_bundle_id) ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), sku = VALUES(sku), wrap_quantity = VALUES(wrap_quantity), barcode = VALUES(barcode), type = VALUES(type), created_by = VALUES(created_by), created_at = VALUES(created_at), job_card_id = VALUES(job_card_id), master_bundle_id = VALUES(master_bundle_id)", TABLE_NAME );
private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, item_id, sku, wrap_quantity, barcode, type, created_by, created_at, job_card_id, master_bundle_id, production) VALUES (:id, :item_id, :sku, :wrap_quantity, :barcode, :type, :created_by, :created_at, :job_card_id, :master_bundle_id, :production) ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), sku = VALUES(sku), wrap_quantity = VALUES(wrap_quantity), barcode = VALUES(barcode), type = VALUES(type), created_by = VALUES(created_by), created_at = VALUES(created_at), job_card_id = VALUES(job_card_id), master_bundle_id = VALUES(master_bundle_id), production = VALUES(production)", TABLE_NAME );
private final String SELECT_BY_TERM_QUERY = String.format( "SELECT * FROM %s WHERE (id = :id OR sku LIKE :sku OR type LIKE :type OR barcode LIKE :barcode) AND master_bundle_id =0", TABLE_NAME );
private final String SELECT_BY_LIMIT = String.format( "SELECT * FROM %s ORDER BY id DESC LIMIT :limit", TABLE_NAME );
private final String SELECT_BY_MASTER_ID = String.format( "SELECT * FROM %s WHERE master_bundle_id = :master_bundle_id ORDER BY id DESC", TABLE_NAME );
private final String SELECT_BY_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", TABLE_NAME );
private final String SELECT_BY_ITEM_ID_AND_JOB_CARD = String.format( "SELECT * FROM %s WHERE item_id = :item_id AND job_card_id = :job_card_id", TABLE_NAME );
private final String SELECT_BY_ITEM_IDS_AND_JOB_CARD = String.format( "SELECT * FROM %s WHERE item_id IN (:item_ids) AND job_card_id = :job_card_id", TABLE_NAME );
private final String SELECT_LIKE_BARCODE = String.format("SELECT * FROM %s WHERE barcode LIKE :barcode", TABLE_NAME);
public BundleDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
@ -40,6 +41,7 @@ public class BundleDAO {
params.addValue( "id", bundle.getId() )
.addValue( "item_id", bundle.getItemId() )
.addValue( "sku", bundle.getSku() )
.addValue("production",bundle.getProduction())
.addValue( "wrap_quantity", bundle.getWrapQuantity() )
.addValue( "barcode", bundle.getBarcode() )
.addValue( "type", bundle.getType() )
@ -61,6 +63,12 @@ public class BundleDAO {
}
public List<Bundle> findByBarcodeLike(String barcode) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("barcode", "%" + barcode + "%");
return namedParameterJdbcTemplate.query(SELECT_LIKE_BARCODE, params, new BundleRowMapper());
}
// find all
public List<Bundle> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new BundleRowMapper() );

View File

@ -16,6 +16,7 @@ public class BundleRowMapper implements RowMapper<Bundle> {
bundle.setBarcode( rs.getString( "barcode" ) );
bundle.setType( rs.getString( "type" ) );
bundle.setCreatedBy( rs.getString( "created_by" ) );
bundle.setProduction(rs.getBigDecimal("production"));
if ( rs.getTimestamp( "created_at" ) != null ) {
bundle.setCreatedAt( rs.getTimestamp( "created_at" ).toLocalDateTime() );
}

View File

@ -21,6 +21,7 @@ public class CutPieceTypeDAO {
private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id 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) VALUES (:id, :title) ON DUPLICATE KEY UPDATE title = VALUES(title)", TABLE_NAME );
private final String SELECT_BY_TITLE = String.format("SELECT * FROM %s WHERE title = :title", TABLE_NAME);
public CutPieceTypeDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
@ -30,7 +31,7 @@ public class CutPieceTypeDAO {
private MapSqlParameterSource prepareInsertQueryParams( CutPieceType cutPieceType ) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", cutPieceType.getId() )
.addValue( "title", cutPieceType.getTitle() );
.addValue( "title", cutPieceType.getType() );
return params;
}
@ -44,6 +45,16 @@ public class CutPieceTypeDAO {
.orElse( new CutPieceType() );
}
// find
public CutPieceType findByTitle( String title ) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "title", title );
return namedParameterJdbcTemplate.query( SELECT_BY_TITLE, params, new CutPieceTypeRowMapper() )
.stream()
.findFirst()
.orElse( new CutPieceType() );
}
// find all
public List<CutPieceType> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new CutPieceTypeRowMapper() );

View File

@ -10,7 +10,7 @@ public class CutPieceTypeRowMapper implements RowMapper<CutPieceType> {
public CutPieceType mapRow( ResultSet rs, int rowNum ) throws SQLException {
CutPieceType cutPieceType = new CutPieceType();
cutPieceType.setId( rs.getLong( "id" ) );
cutPieceType.setTitle( rs.getString( "title" ) );
cutPieceType.setType( rs.getString( "title" ) );
return cutPieceType;
}
}

View File

@ -1,6 +1,7 @@
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;
@ -22,6 +23,7 @@ public class JobCardItemDAO {
private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id DESC", TABLE_NAME );
private final String DELETE_QUERY = String.format( "DELETE FROM %s WHERE id = :id", TABLE_NAME );
private final String SELECT_BY_CARD_ID = String.format( "SELECT * FROM %s WHERE job_card_id = :card_id", TABLE_NAME );
private final String SELECT_BY_CARD_ID_AND_ITEM_ID = String.format( "SELECT * FROM %s WHERE job_card_id = :card_id AND item_id = :item_id ", TABLE_NAME );
private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, job_card_id, item_id, sku, expected_production, actual_production, total_production, account_id, length, width, gsm, wt_ply, ply) VALUES (:id, :job_card_id, :item_id, :sku, :expected_production, :actual_production, :total_production, :account_id, :length, :width, :gsm, :wt_ply, :ply) ON DUPLICATE KEY UPDATE job_card_id = VALUES(job_card_id), item_id = VALUES(item_id), sku = VALUES(sku), expected_production = VALUES(expected_production), actual_production = VALUES(actual_production), total_production = VALUES(total_production), account_id = VALUES(account_id), length = VALUES(length), width = VALUES(width), gsm = VALUES(gsm), wt_ply = VALUES(wt_ply), ply = VALUES(ply) ", TABLE_NAME );
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 actual_production = :actual_production AND account_id IN (:account_ids)", TABLE_NAME );
@ -95,6 +97,15 @@ public class JobCardItemDAO {
return namedParameterJdbcTemplate.query(SELECT_BY_CARD_ID, params, new JobCardItemRowMapper() );
}
public JobCardItem findByCardIdAndItemId( long cardId,long itemItem ){
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "card_id", cardId );
params.addValue("item_id",itemItem);
return namedParameterJdbcTemplate.query(SELECT_BY_CARD_ID_AND_ITEM_ID, params, new JobCardItemRowMapper() ).stream()
.findFirst()
.orElse( new JobCardItem() );
}
public List<JobCardItem> findByIds( List<Long> ids ){
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "ids", ids );

View File

@ -20,10 +20,12 @@ public class MasterBundleDAO {
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 ORDER BY id 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, barcode,item_id, sku, created_by, created_at, job_card_id, is_received) VALUES (:id, :barcode, :item_id, :sku, :created_by, :created_at, :job_card_id, :is_received) ON DUPLICATE KEY UPDATE barcode = VALUES(barcode), item_id = VALUES(item_id), sku = VALUES(sku), created_by = VALUES(created_by), created_at = VALUES(created_at), job_card_id = VALUES(job_card_id), is_received = VALUES(is_received)", TABLE_NAME );
private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, barcode,item_id, sku, created_by, created_at, job_card_id, account_id, is_received) VALUES (:id, :barcode, :item_id, :sku, :created_by, :created_at, :job_card_id, :account_id, :is_received) ON DUPLICATE KEY UPDATE barcode = VALUES(barcode), item_id = VALUES(item_id), sku = VALUES(sku), created_by = VALUES(created_by), created_at = VALUES(created_at), job_card_id = VALUES(job_card_id), is_received = VALUES(is_received), account_id = VALUES(account_id) ", TABLE_NAME );
private final String SELECT_BY_LIMIT = String.format( "SELECT * FROM %s ORDER BY id DESC LIMIT :limit", TABLE_NAME );
private final String SELECT_BY_TERM_AND_RECEIVED = String.format( "SELECT * FROM %s WHERE is_received = :is_received AND ( id LIKE :id OR barcode LIKE :barcode ) ", TABLE_NAME );
private final String SELECT_BY_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", TABLE_NAME );
private final String SELECT_BY_IDS_AND_RECIEVE = String.format( "SELECT id FROM %s WHERE id IN (:ids) AND is_received = true", TABLE_NAME );
public MasterBundleDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
@ -37,6 +39,7 @@ public class MasterBundleDAO {
.addValue( "barcode", masterBundle.getBarcode() )
.addValue( "item_id", masterBundle.getItemId() )
.addValue( "sku", masterBundle.getSku() )
.addValue( "account_id", masterBundle.getAccountId() )
.addValue( "created_by", masterBundle.getCreatedBy() )
.addValue( "created_at", masterBundle.getCreatedAt() )
.addValue( "job_card_id", masterBundle.getJobCardId() )
@ -54,6 +57,13 @@ public class MasterBundleDAO {
.orElse( new MasterBundle() );
}
// find all
public List<Long> findByIdAndReceiveIsTrue(List<Long> ids) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "ids", ids );
return namedParameterJdbcTemplate.query(SELECT_BY_IDS_AND_RECIEVE, params, (rs, rowNum) -> rs.getLong("id"));
}
// find all
public List<MasterBundle> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new MasterBundleRowMapper() );

View File

@ -14,6 +14,7 @@ public class MasterBundleRowMapper implements RowMapper<MasterBundle> {
masterBundle.setCreatedBy( rs.getString( "created_by" ) );
masterBundle.setItemId( rs.getLong("item_id" ));
masterBundle.setSku( rs.getString("sku" ) );
masterBundle.setAccountId(rs.getLong("account_id"));
if ( rs.getTimestamp( "created_at" ) != null ) {
masterBundle.setCreatedAt( rs.getTimestamp( "created_at" ).toLocalDateTime() );
}

View File

@ -0,0 +1,18 @@
package com.utopiaindustries.dao.ctp;
import com.utopiaindustries.model.ctp.CutPiece;
import com.utopiaindustries.model.ctp.SkuCutPieces;
import org.springframework.jdbc.core.RowMapper;
import java.sql.ResultSet;
import java.sql.SQLException;
public class SkuCutPieceRowMapper implements RowMapper<SkuCutPieces> {
public SkuCutPieces mapRow(ResultSet rs, int rowNum) throws SQLException {
SkuCutPieces skuCutPieces = new SkuCutPieces();
skuCutPieces.setId(rs.getLong("id"));
skuCutPieces.setSku(rs.getString("sku"));
skuCutPieces.setType(rs.getString("title"));
return skuCutPieces;
}
}

View File

@ -0,0 +1,96 @@
package com.utopiaindustries.dao.ctp;
import com.utopiaindustries.model.ctp.CutPieceType;
import com.utopiaindustries.model.ctp.SkuCutPieces;
import com.utopiaindustries.util.KeyHolderFunctions;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.support.GeneratedKeyHolder;
import org.springframework.jdbc.support.KeyHolder;
import org.springframework.stereotype.Repository;
import java.util.ArrayList;
import java.util.List;
@Repository
public class SkuCutPiecesDAO {
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private final String TABLE_NAME = "cut_to_pack.sku_cut_piece";
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 ORDER BY id 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 (sku, title) VALUES (:sku, :title) ON DUPLICATE KEY UPDATE sku = VALUES(sku), title = VALUES(title)", TABLE_NAME);
private final String FIND_BY_SKU = String.format( "SELECT * FROM %s WHERE sku = :sku", TABLE_NAME );
private final String CHECK_EXISTENCE_QUERY = String.format("SELECT COUNT(*) FROM %s WHERE title = :title AND sku = :sku", TABLE_NAME);
public SkuCutPiecesDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
}
// prepare query params
private MapSqlParameterSource prepareInsertQueryParams(SkuCutPieces skuCutPieces ) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", skuCutPieces.getId() )
.addValue( "sku", skuCutPieces.getSku())
.addValue("title",skuCutPieces.getType());
return params;
}
// find
public SkuCutPieces find( long id ) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", id );
return namedParameterJdbcTemplate.query( SELECT_QUERY, params, new SkuCutPieceRowMapper() )
.stream()
.findFirst()
.orElse( new SkuCutPieces() );
}
public boolean doesExist(String type, String sku) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("title", type);
params.addValue("sku", sku);
Long count = namedParameterJdbcTemplate.queryForObject(CHECK_EXISTENCE_QUERY, params, Long.class);
return count > 0;
}
//find by sku
public List<SkuCutPieces> findBySku(String sku) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("sku", sku);
return namedParameterJdbcTemplate.query(FIND_BY_SKU, params, new SkuCutPieceRowMapper());
}
// find all
public List<CutPieceType> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new CutPieceTypeRowMapper() );
}
// save
public long save( SkuCutPieces skuCutPieces ) {
KeyHolder keyHolder = new GeneratedKeyHolder();
MapSqlParameterSource params = prepareInsertQueryParams( skuCutPieces );
namedParameterJdbcTemplate.update( INSERT_QUERY, params, keyHolder );
return KeyHolderFunctions.getKey( skuCutPieces.getId(), keyHolder );
}
// save all
public int[] saveAll( List<SkuCutPieces> skuCutPieces ) {
List<MapSqlParameterSource> batchArgs = new ArrayList<>();
for ( SkuCutPieces cutPieceType: skuCutPieces ) {
MapSqlParameterSource params = prepareInsertQueryParams( cutPieceType );
batchArgs.add( params );
}
return namedParameterJdbcTemplate.batchUpdate( INSERT_QUERY, batchArgs.toArray(new MapSqlParameterSource[skuCutPieces.size()]) );
}
// delete
public boolean delete( long id ) {
MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", id );
return namedParameterJdbcTemplate.update( DELETE_QUERY, params ) > 0;
}
}

View File

@ -22,7 +22,7 @@ public class StitchingOfflineItemDAO {
private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id DESC", TABLE_NAME );
private final String SELECT_QUERY_BY_JOB_CARD = String.format( "SELECT * FROM %s WHERE job_card_id = :job_card_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( "INSERT INTO %s (id, item_id, sku, barcode, created_at, created_by, job_card_id, is_qa, qa_remarks, qa_status) VALUES (:id, :item_id, :sku, :barcode, :created_at, :created_by, :job_card_id, :is_qa, :qa_remarks, :qa_status) ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), sku = VALUES(sku), barcode = VALUES(barcode), created_at = VALUES(created_at), created_by = VALUES(created_by), job_card_id = VALUES(job_card_id), is_qa = VALUES(is_qa), qa_remarks = VALUES(qa_remarks), qa_status = VALUES(qa_status)", TABLE_NAME );
private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, item_id, sku, barcode, created_at, created_by, job_card_id, is_qa, qa_remarks, qa_status,bundle_id) VALUES (:id, :item_id, :sku, :barcode, :created_at, :created_by, :job_card_id, :is_qa, :qa_remarks, :qa_status, :bundle_id) ON DUPLICATE KEY UPDATE item_id = VALUES(item_id), sku = VALUES(sku), barcode = VALUES(barcode), created_at = VALUES(created_at), created_by = VALUES(created_by), job_card_id = VALUES(job_card_id), is_qa = VALUES(is_qa), qa_remarks = VALUES(qa_remarks), qa_status = VALUES(qa_status), bundle_id = VALUES(bundle_id)", TABLE_NAME );
private final String SELECT_BY_LIMIT = String.format("SELECT * FROM %s ORDER BY id DESC LIMIT :limit", TABLE_NAME );
private final String FIND_TOTAL_COUNT = String.format("SELECT COUNT(*) FROM %s where job_card_id = :job_card_id And item_id = :item_id", TABLE_NAME );
private final String SELECT_BY_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", TABLE_NAME );
@ -40,6 +40,7 @@ public class StitchingOfflineItemDAO {
.addValue( "item_id", stitchingOfflineItem.getItemId() )
.addValue( "sku", stitchingOfflineItem.getSku() )
.addValue( "barcode", stitchingOfflineItem.getBarcode() )
.addValue("bundle_id",stitchingOfflineItem.getBundleId())
.addValue( "created_at", stitchingOfflineItem.getCreatedAt() )
.addValue( "created_by", stitchingOfflineItem.getCreatedBy() )
.addValue("job_card_id", stitchingOfflineItem.getJobCardId() )

View File

@ -15,6 +15,7 @@ public class StitchingOfflineItemRowMapper implements RowMapper<StitchingOffline
stitchingOfflineItem.setItemId( rs.getLong( "item_id" ) );
stitchingOfflineItem.setSku( rs.getString( "sku" ) );
stitchingOfflineItem.setBarcode( rs.getString( "barcode" ) );
stitchingOfflineItem.setBundleId(rs.getLong("bundle_id"));
if ( rs.getTimestamp( "created_at" ) != null ) {
stitchingOfflineItem.setCreatedAt( rs.getTimestamp( "created_at" ).toLocalDateTime() );
}

View File

@ -22,7 +22,7 @@ public class SummaryInventoryReportDao {
+ "(:sku IS NULL OR sku = :sku) "
+ "AND (:item_id IS NULL OR item_id = :item_id) "
+ "OR (:start_date IS NULL OR :end_date IS NULL OR transaction_leg_datetime BETWEEN :start_date AND :end_date) "
+ "GROUP BY DATE(transaction_leg_datetime), sku, parent_document_type, parent_document_piece_type "
+ "GROUP BY DATE(transaction_leg_datetime), account_id, sku, parent_document_type, parent_document_piece_type "
+ "ORDER BY transaction_date, sku;";
public SummaryInventoryReportDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {

View File

@ -6,8 +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, 200, 10, 40, 6, 50, 40, 125, 125, 14, 9, 7),
SIZE_1_X_2( 67.69f, 125.73f ,10 , 10, 20, 6, 60, 60, 125, 125, 4, 9, 7);
private final float width;
private final float height;

View File

@ -11,6 +11,8 @@ public class Bundle implements InventoryArtifact {
private long itemId;
private String sku;
private BigDecimal wrapQuantity;
private BigDecimal production;
private BigDecimal currentProduction;
private String barcode;
private String type;
private String createdBy;
@ -98,6 +100,22 @@ public class Bundle implements InventoryArtifact {
return masterBundleId;
}
public BigDecimal getProduction() {
return production;
}
public void setProduction(BigDecimal production) {
this.production = production;
}
public BigDecimal getCurrentProduction() {
return currentProduction;
}
public void setCurrentProduction(BigDecimal currentProduction) {
this.currentProduction = currentProduction;
}
public void setMasterBundleId(long masterBundleId) {
this.masterBundleId = masterBundleId;
}
@ -110,6 +128,10 @@ public class Bundle implements InventoryArtifact {
this.masterBundle = masterBundle;
}
public long getBundleId(){
return 0;
}
@Override
public String toString() {
return "Bundle{" +

View File

@ -0,0 +1,16 @@
package com.utopiaindustries.model.ctp;
import java.util.ArrayList;
import java.util.List;
public class BundleWrapper {
private List<Bundle> bundles = new ArrayList<>(); // ✅ Initialize List
public List<Bundle> getBundles() {
return bundles;
}
public void setBundles(List<Bundle> bundles) {
this.bundles = bundles;
}
}

View File

@ -3,7 +3,7 @@ package com.utopiaindustries.model.ctp;
public class CutPieceType {
private long id;
private String title;
private String type;
public long getId() {
return id;
@ -13,19 +13,19 @@ public class CutPieceType {
this.id = id;
}
public String getTitle() {
return title;
public String getType() {
return type;
}
public void setTitle(String title) {
this.title = title;
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "CutPieceType{" +
"id=" + id +
", title='" + title + '\'' +
", title='" + type + '\'' +
'}';
}
}

View File

@ -2,6 +2,7 @@ package com.utopiaindustries.model.ctp;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
public class FinishedItem implements InventoryArtifact {
@ -141,6 +142,18 @@ public class FinishedItem implements InventoryArtifact {
this.qaStatus = qaStatus;
}
public BigDecimal getWrapQuantity(){
return null;
}
public long getMasterBundleId(){
return 0;
}
public long getBundleId(){
return 0;
}
@Override
public String toString() {
return "FinishedItem{" +

View File

@ -1,11 +1,19 @@
package com.utopiaindustries.model.ctp;
import java.math.BigDecimal;
import java.time.LocalDateTime;
public interface InventoryArtifact {
long getId();
long getItemId();
long getJobCardId();
String getSku();
String getType();
String getBarcode();
String getCreatedBy();
LocalDateTime getCreatedAt();
BigDecimal getWrapQuantity();
long getMasterBundleId();
long getBundleId();
}

View File

@ -3,5 +3,7 @@ package com.utopiaindustries.model.ctp;
public enum InventoryArtifactType {
BUNDLE,
STITCHING_OFFLINE,
FINISHED_ITEM
FINISHED_ITEM,
STITCH_BUNDLE
}

View File

@ -1,5 +1,6 @@
package com.utopiaindustries.model.ctp;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@ -13,6 +14,8 @@ public class MasterBundle implements InventoryArtifact{
private LocalDateTime createdAt;
private boolean isReceived;
private long jobCardId;
private long accountId;
// wrapper
private List<Bundle> bundles;
private List<FinishedItem> items;
@ -94,6 +97,14 @@ public class MasterBundle implements InventoryArtifact{
this.bundles = bundles;
}
public BigDecimal getWrapQuantity(){
return null;
}
public long getMasterBundleId(){
return 0;
}
public List<FinishedItem> getItems() {
return items;
}
@ -102,6 +113,18 @@ public class MasterBundle implements InventoryArtifact{
this.items = items;
}
public long getAccountId() {
return accountId;
}
public void setAccountId(long accountId) {
this.accountId = accountId;
}
public long getBundleId(){
return 0;
}
@Override
public String toString() {
return "MasterBundle{" +

View File

@ -0,0 +1,43 @@
package com.utopiaindustries.model.ctp;
public class SkuCutPieces {
private long id;
private String sku;
private String type;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getSku() {
return sku;
}
public void setSku(String sku) {
this.sku = sku;
}
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@Override
public String toString() {
return "CutPiece{" +
"id=" + id +
", sku=" + sku +
", type='" + type +
'}';
}
}

View File

@ -2,6 +2,7 @@ package com.utopiaindustries.model.ctp;
import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime;
public class StitchingOfflineItem implements InventoryArtifact {
@ -17,6 +18,7 @@ public class StitchingOfflineItem implements InventoryArtifact {
private boolean isQa;
private String qaRemarks;
private String qaStatus;
private long bundleId;
@Override
public String getType() {
@ -107,6 +109,22 @@ public class StitchingOfflineItem implements InventoryArtifact {
this.qaStatus = qaStatus;
}
public BigDecimal getWrapQuantity(){
return null;
}
public long getMasterBundleId(){
return 0;
}
public long getBundleId() {
return bundleId;
}
public void setBundleId(long bundleId) {
this.bundleId = bundleId;
}
@Override
public String toString() {
return "StitchingOfflineItem{" +

View File

@ -34,4 +34,13 @@ public class BundleRestController {
return bundleService.findBundlesByMasterId( masterId );
}
@GetMapping( "/find-bundle-by-id/{id}" )
public Bundle findBundleById( @PathVariable("id") long id ){
return bundleService.getBundlesById(id);
}
@GetMapping( "/find-bundle-by-barcode" )
public List<Bundle> findByMasterBarcode(@RequestParam String term ){
return bundleService.getBundles( term );
}
}

View File

@ -1,19 +1,42 @@
package com.utopiaindustries.restcontroller;
import com.utopiaindustries.dao.ctp.CutPieceTypeDAO;
import com.utopiaindustries.dao.ctp.SkuCutPiecesDAO;
import com.utopiaindustries.model.ctp.CutPieceType;
import com.utopiaindustries.model.ctp.SkuCutPieces;
import com.utopiaindustries.service.JobCardService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@RestController
@RequestMapping( "/rest/cut-pieces" )
public class CutPieceRestController {
private final JobCardService jobCardService;
private final SkuCutPiecesDAO skuCutPiecesDAO;
private final CutPieceTypeDAO cutPieceTypeDAO;
public CutPieceRestController(JobCardService jobCardService) {
public CutPieceRestController(JobCardService jobCardService, SkuCutPiecesDAO skuCutPiecesDAO, CutPieceTypeDAO cutPieceTypeDAO) {
this.jobCardService = jobCardService;
this.skuCutPiecesDAO = skuCutPiecesDAO;
this.cutPieceTypeDAO = cutPieceTypeDAO;
}
@GetMapping
public List<CutPieceType> getBySku(@RequestParam("sku") String sku) {
try {
ArrayList<CutPieceType> cutPieceTypes = new ArrayList<>();
List<SkuCutPieces> skuCutPieces = skuCutPiecesDAO.findBySku(sku);
for (SkuCutPieces skuCutPieces1 : skuCutPieces){
CutPieceType cutPieceType = cutPieceTypeDAO.findByTitle(skuCutPieces1.getType());
cutPieceTypes.add(cutPieceType);
}
return cutPieceTypes;
} catch (Exception e) {
throw new RuntimeException("An error occurred while fetching data for SKU: " + sku, e);
}
}
@PostMapping

View File

@ -1,10 +1,18 @@
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.itextpdf.io.font.constants.StandardFonts;
import com.itextpdf.io.image.ImageData;
import com.itextpdf.kernel.colors.ColorConstants;
import com.itextpdf.kernel.font.PdfFont;
import com.itextpdf.kernel.font.PdfFontFactory;
import com.itextpdf.kernel.pdf.PdfPage;
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
import com.itextpdf.layout.element.AreaBreak;
import com.itextpdf.layout.element.Paragraph;
import com.itextpdf.layout.property.AreaBreakType;
import com.itextpdf.layout.property.TextAlignment;
import com.utopiaindustries.dao.ctp.*;
import com.utopiaindustries.model.ctp.*;
import com.utopiaindustries.util.BarcodeUtils;
import com.utopiaindustries.util.StringUtils;
@ -13,17 +21,39 @@ import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.graphics.internal.ZebraImage;
import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import com.itextpdf.io.image.ImageDataFactory;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.geom.PageSize;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.layout.Document;
import com.itextpdf.layout.element.Image;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.net.Socket;
import java.nio.file.Path;
import java.nio.file.FileSystems;
import java.awt.*;
import java.awt.Font;
import java.awt.image.BufferedImage;
import java.io.ByteArrayInputStream;
import java.io.*;
import java.time.format.DateTimeFormatter;
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 {
@ -34,16 +64,34 @@ public class BarcodeService {
@Value("${ctp.printer.port}")
private int port;
@Value("${ctp.printer.bundleIpAdd}")
private String bundleIpAddress;
@Value("${ctp.printer.bundlePort}")
private int bundlePort;
@Value("${ctp.printer.stitchQRPath}")
private String stitchPath;
@Value("${ctp.printer.bundlePath}")
private String bundlePath;
private final BundleDAO bundleDAO;
private final JobCardDAO jobCardDAO;
private final MasterBundleDAO masterBundleDAO;
private final FinishedItemDAO finishedItemDAO;
private final StitchingOfflineItemDAO stitchingOfflineItemDAO;
private final InventoryAccountDAO inventoryAccountDAO;
private final JobCardItemDAO jobCardItemDAO;
public BarcodeService(BundleDAO bundleDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) {
public BarcodeService(BundleDAO bundleDAO, JobCardDAO jobCardDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO, InventoryAccountDAO inventoryAccountDAO, JobCardItemDAO jobCardItemDAO) {
this.bundleDAO = bundleDAO;
this.jobCardDAO = jobCardDAO;
this.masterBundleDAO = masterBundleDAO;
this.finishedItemDAO = finishedItemDAO;
this.stitchingOfflineItemDAO = stitchingOfflineItemDAO;
this.inventoryAccountDAO = inventoryAccountDAO;
this.jobCardItemDAO = jobCardItemDAO;
}
/*
@ -56,85 +104,364 @@ 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);
}
getBarcodeImages(list, stickerSize, artifactType);
}
public void getBarcodeImages(List<? extends InventoryArtifact> artifacts,
BarcodeStickerSize stickerSize,
String artifactType) throws Exception {
for (InventoryArtifact artifact : artifacts) {
// Create a blank BufferedImage (an image with the size of the sticker)
BufferedImage stickerImage = new BufferedImage((int) stickerSize.getWidth()*2, (int) stickerSize.getHeight()*2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = stickerImage.createGraphics();
g2d.scale(2,2);
BarcodeStickerSize stickerSize,
String artifactType) throws Exception {
int pageWidth = 900; // A4 Width
int pageHeight = 1200; // A4 Height
int rows = 3;
int cols = 2;
int totalStickersPerPage = rows * cols;
int totalPages = (int) Math.ceil((double) artifacts.size() / totalStickersPerPage); // Total required pages
List<BufferedImage> bufferedImages = new ArrayList<>();
for (int page = 0; page < totalPages; page++) {
// Create a Blank A4 Page Image
BufferedImage a4Image = new BufferedImage(pageWidth, pageHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = a4Image.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set background color (white for the sticker)
g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, (int) stickerSize.getWidth(), (int) stickerSize.getHeight());
// Set font for SKU and barcode
Font font = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10);
g2d.setFont(font);
// Add SKU to the image
String sku = artifact.getSku();
FontMetrics fontMetrics = g2d.getFontMetrics();
int textWidth = fontMetrics.stringWidth(sku);
int x = (int) ((stickerSize.getWidth() - textWidth) / 2);
g2d.fillRect(0, 0, pageWidth, pageHeight);
g2d.setColor(Color.BLACK);
g2d.drawString(sku, x, stickerSize.getMarginTop() + fontMetrics.getAscent()+20);
// Create the barcode image
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode()+500, stickerSize.getImageHeightBarcode()+30);
BufferedImage barcodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
Font barcodeFont = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+8);
Font detailFont = new Font("Helvetica", Font.PLAIN, stickerSize.getTextSize()+3);
// Draw the barcode image on the sticker
int barcodeX =(int) (stickerSize.getWidth() - barcodeImage.getWidth()) / 2;
int barcodeY = stickerSize.getMarginTop() + fontMetrics.getAscent() + 30; // Add some margin
g2d.drawImage(barcodeImage, barcodeX, barcodeY, null);
for (int i = 0; i < totalStickersPerPage; i++) {
int artifactIndex = page * totalStickersPerPage + i;
if (artifactIndex >= artifacts.size()) break;
InventoryArtifact artifact = artifacts.get(artifactIndex);
int row = i / cols;
int col = i % cols;
// Add the barcode value below the barcode image
g2d.drawString(artifact.getBarcode(), (stickerSize.getWidth() - fontMetrics.stringWidth(artifact.getBarcode())) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent());
int x = col * (pageWidth / cols);
int y = row * (pageHeight / rows);
// If artifactType is Bundle, add additional info
if (artifactType.equalsIgnoreCase(Bundle.class.getSimpleName())) {
String typeText = String.format("%s : %d", artifact.getType(), artifact.getId());
g2d.drawString(typeText, (stickerSize.getWidth() - fontMetrics.stringWidth(typeText)) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
Font stickerFont = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize() + 10);
g2d.setFont(stickerFont);
// Draw Sticker Border
g2d.drawRect(x, y, pageWidth / cols, pageHeight / rows);
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+20));
g2d.drawString(String.valueOf(artifactType.toCharArray()[0]), (stickerSize.getWidth() - fontMetrics.stringWidth(String.valueOf(artifactType.toCharArray()[0]))) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 77);
} else {
// Add first character of artifact type
String type = String.valueOf(artifactType.charAt(0));
g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10));
g2d.drawString(type, (stickerSize.getWidth() - fontMetrics.stringWidth(type)) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
this.drawCenteredText(g2d, artifactType.equals("Bundle")?"Sub-Bundle":"Master-Bundle", detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop()-20,stickerSize.getMarginLeft()-165);
// Draw SKU
g2d.setFont(barcodeFont);
String sku = artifact.getSku();
FontMetrics fontMetrics = g2d.getFontMetrics();
int textWidth = fontMetrics.stringWidth(sku);
g2d.drawString(sku, x + ((pageWidth / cols) - textWidth) / 2, y + fontMetrics.getAscent()+ stickerSize.getMarginTop()+10);
// Generate Barcode Image
g2d.setFont(barcodeFont);
byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(
artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
BufferedImage barcodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
int originalBarcodeWidth = barcodeImage.getWidth();
int originalBarcodeHeight = barcodeImage.getHeight();
double scaleX = (double)(pageWidth / cols) / originalBarcodeWidth;
double scaleY = (double)(pageHeight / rows) / originalBarcodeHeight;
double scaleFactor = Math.min(scaleX, scaleY);
int scaledWidth = (int)(originalBarcodeWidth * scaleFactor) - 30;
int scaledHeight = (int)(originalBarcodeHeight * scaleFactor) - 10;
BufferedImage scaledBarcodeImage = new BufferedImage(scaledWidth, scaledHeight, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2dBarcode = scaledBarcodeImage.createGraphics();
g2dBarcode.drawImage(barcodeImage, 0, 0, scaledWidth, scaledHeight, null);
g2dBarcode.dispose();
int barcodeX = x + ((pageWidth / cols) - scaledBarcodeImage.getWidth()) / 2;
int barcodeY = y + fontMetrics.getAscent() + stickerSize.getMarginTop() + 20;
g2d.drawImage(scaledBarcodeImage, barcodeX, barcodeY, null);
//barcode text
g2d.setFont(barcodeFont);
String barcode = artifact.getBarcode();
FontMetrics barcodeFontMatrix = g2d.getFontMetrics();
int barcodeText = fontMetrics.stringWidth(barcode);
g2d.drawString(barcode, (x + ((pageWidth / cols) - barcodeText) / 2), y + barcodeFontMatrix.getAscent() + stickerSize.getMarginTop() + 120);
//draw item-id
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy hh:mm");
this.drawCenteredText(g2d, "Item-ID: "+artifact.getItemId(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 150,stickerSize.getMarginLeft());
this.drawCenteredText(g2d, "Created-By: "+artifact.getCreatedBy(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 170,stickerSize.getMarginLeft());
this.drawCenteredText(g2d, "Created-At: "+formatter.format(artifact.getCreatedAt()), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 190,stickerSize.getMarginLeft());
//draw job-card details
JobCard jobCard = jobCardDAO.find(artifact.getJobCardId());
this.drawCenteredText(g2d, "Job-Card: " + jobCard.getCode(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 210, stickerSize.getMarginLeft() );
this.drawCenteredText(g2d, "Purchase-Order: " + jobCard.getPurchaseOrderId(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 230, stickerSize.getMarginLeft());
this.drawCenteredText(g2d, "Lot-Number: " + jobCard.getLotNumber(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 250, stickerSize.getMarginLeft());
if((artifactType.equals("Bundle"))){
JobCardItem jobCardItem = jobCardItemDAO.findByCardId(jobCard.getId()).get(0);
InventoryAccount inventoryAccount = inventoryAccountDAO.find(jobCardItem.getAccountId());
this.drawCenteredText(g2d, "Pieces: " + artifact.getWrapQuantity(), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 270, stickerSize.getMarginLeft());
this.drawCenteredText(g2d, "Cutting-Account: " + inventoryAccount.getTitle() , detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 290, stickerSize.getMarginLeft());
}else {
List<Bundle> bundles = bundleDAO.findByMasterId(artifact.getId());
String concatenatedIds = bundles.stream()
.map(bundle -> String.valueOf(bundle.getId()))
.collect(Collectors.joining("\\"));
this.drawCenteredText(g2d, "Sub-Bundles: " + concatenatedIds, detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 290, stickerSize.getMarginLeft());
}
this.drawCenteredText(g2d, String.valueOf(artifact.getId()), detailFont, x, y, pageWidth, cols, stickerSize.getMarginTop() + 330, 0);
}
// Finalize drawing
g2d.dispose();
printLabel(stickerImage);
bufferedImages.add(a4Image);
}
saveA4ImageToPDF(bufferedImages,bundlePath);
try {
printPDF(bundleIpAddress, bundlePath);
} catch (Exception e) {
e.printStackTrace();
}
}
public void printLabel( BufferedImage bufferedImage ) throws Exception {
Connection connection = new TcpConnection( ipAddress, port );
public void printPDF(String printerIP, String pdfFilePath) throws Exception {
File pdfFile = new File(pdfFilePath);
FileInputStream fis = new FileInputStream(pdfFile);
Socket printerSocket = new Socket(printerIP, port);
OutputStream out = printerSocket.getOutputStream();
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
out.flush();
out.close();
fis.close();
printerSocket.close();
}
public void saveA4ImageToPDF(List<BufferedImage> a4Images, String outputFilePath) throws Exception {
PdfWriter writer = new PdfWriter(outputFilePath);
PdfDocument pdfDoc = new PdfDocument(writer);
Document document = new Document(pdfDoc, PageSize.A4);
document.setMargins(0, 0, 0, 0);
for (int i = 0; i < a4Images.size(); i++) {
if (i > 0) {
document.add(new AreaBreak(AreaBreakType.NEXT_PAGE));
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(a4Images.get(i), "png", baos);
byte[] imageBytes = baos.toByteArray();
ImageData imageData = ImageDataFactory.create(imageBytes);
Image image = new Image(imageData);
// Scale and position correctly
image.scaleToFit(pdfDoc.getDefaultPageSize().getWidth(), pdfDoc.getDefaultPageSize().getHeight());
image.setFixedPosition(0, 30);
document.add(image);
}
document.close();
}
private void drawCenteredText(Graphics2D g2d, String text, Font font, int x, int y, int pageWidth, int cols, int marginTop, int marginLeft) {
g2d.setFont(font);
FontMetrics fontMetrics = g2d.getFontMetrics();
int adjustedX = (x + ((pageWidth / cols) ) / 2) - marginLeft;
int adjustedY = y + fontMetrics.getAscent() + marginTop;
g2d.drawString(text, adjustedX, adjustedY);
}
public void getBarcodeImagesForStitchItems(List<? extends InventoryArtifact> artifacts,
BarcodeStickerSize stickerSize) throws Exception {
Path pdfPath = FileSystems.getDefault().getPath(stitchPath);
PdfWriter writer = new PdfWriter(pdfPath.toFile());
PdfDocument pdfDoc = new PdfDocument(writer);
Document document = new Document(pdfDoc);
pdfDoc.setDefaultPageSize(new PageSize(stickerSize.getWidth(), stickerSize.getHeight()));
for (InventoryArtifact artifact : artifacts) {
JobCard jobCard = jobCardDAO.find(artifact.getJobCardId());
PdfPage page = pdfDoc.addNewPage();
PdfCanvas canvas = new PdfCanvas(page);
canvas.setFillColor(ColorConstants.WHITE);
canvas.rectangle(0, 0, stickerSize.getWidth(), stickerSize.getHeight());
canvas.fill();
// Draw QR Code on Left Side
byte[] imgBytes = generateQRCodeImageByteArray(artifact.getBarcode(), stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
Image qrCodeImage = new Image(ImageDataFactory.create(imgBytes));
float qrY =stickerSize.getMarginLeft()+50 ;
float qrX = stickerSize.getMarginTop();
qrCodeImage.setFixedPosition(qrX - 16, qrY-47);
document.add(qrCodeImage);
float textX = stickerSize.getMarginLeft() + 40;
float textY = stickerSize.getMarginTop() + 40;
String sku = artifact.getSku();
String jobCardCode = jobCard.getCode();
String combinedText = sku + " \\ " + jobCardCode + " \\ " + artifact.getBundleId();
combinedText = combinedText.replaceAll("\\s+", "");
int maxLength = 14;
List<String> 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())).replaceAll("\\s+", "");
lines.add(part);
}
}
float labelWidth = 67.69f;
float textBoxWidth = 220;
float textY1 = textY-30;
float textXCenter = textX + (labelWidth / 2) - (textBoxWidth / 2)-50;
for (String line : lines) {
Paragraph rotatedText = new Paragraph(line)
.setFontColor(ColorConstants.BLACK)
.setFontSize(stickerSize.getTextSize() + 2)
.setTextAlignment(TextAlignment.CENTER)
.setFixedPosition(textXCenter, textY1-18, textBoxWidth);
document.add(rotatedText);
textY1 -= 6;
}
PdfFont font = PdfFontFactory.createFont(StandardFonts.COURIER_OBLIQUE);
String id = String.valueOf(artifact.getId());
document.add(new Paragraph(id)
.setFont(font)
.setFontColor(ColorConstants.BLACK)
.setBold()
.setFontSize(stickerSize.getTextSize() + 8)
.setTextAlignment(TextAlignment.LEFT)
.setFixedPosition(textX - 25, textY + 8, 140));
float dottedLine = textY - 60;
for(int i= 0 ;i<16;i++){
document.add(new Paragraph("|")
.setFontSize(stickerSize.getTextSize())
.setFontColor(ColorConstants.BLACK)
.setBold()
.setRotationAngle(-Math.PI / 2)
.setTextAlignment(TextAlignment.LEFT)
.setFixedPosition(dottedLine,textX+40, 100));
dottedLine += 7;
}
float dottedLine2 = textY - 60;
for(int i= 0 ;i<16;i++){
document.add(new Paragraph("|")
.setFontSize(stickerSize.getTextSize())
.setFontColor(ColorConstants.BLACK)
.setBold()
.setRotationAngle(-Math.PI / 2)
.setTextAlignment(TextAlignment.LEFT)
.setFixedPosition(dottedLine2,textX+75, 100));
dottedLine2 += 7;
}
if (!artifact.equals(artifacts.get(artifacts.size() - 1))) {
document.add(new AreaBreak());
}
}
if (pdfDoc.getNumberOfPages() > artifacts.size()) {
pdfDoc.removePage(pdfDoc.getNumberOfPages());
}
document.close();
sendPdfToZebraPrinter(pdfPath.toFile());
}
public void sendPdfToZebraPrinter(File pdfFile) throws Exception {
PDDocument pdDocument = PDDocument.load(pdfFile);
PDFRenderer renderer = new PDFRenderer(pdDocument);
for (int pageIndex = 0; pageIndex < pdDocument.getNumberOfPages(); pageIndex++) {
BufferedImage pageImage = renderer.renderImageWithDPI(pageIndex, 320);
printLabel(pageImage);
}
pdDocument.close();
}
public byte[] generateQRCodeImageByteArray(String data, int width, int height) {
try {
QRCodeWriter qrCodeWriter = new QRCodeWriter();
Map<EncodeHintType, Object> hintMap = new HashMap<>();
hintMap.put(EncodeHintType.MARGIN, 0);
BitMatrix bitMatrix = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, width, height, hintMap);
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();
ZebraPrinter printer = ZebraPrinterFactory.getInstance( connection );
ZebraImage zebraImage = new ZebraImage( bufferedImage );
printer.printImage( zebraImage, 0, 0, 0, 0, false );
ZebraPrinter printer = ZebraPrinterFactory.getInstance(connection);
//Reset Printer Settings
String resetSettings = "^XA^JUS^XZ";
printer.sendCommand(resetSettings);
//Force Label Length & Disable Auto Feed
String lengthFix = "^XA^LL555^PON^XZ"; // **Reduce Length (880) & Disable Auto Feed
printer.sendCommand(lengthFix);
//Apply New Settings
String settings = "^XA" +
"^MMT" + // Continuous Mode
"^MTT" + // Thermal Transfer Mode
"^LH0,0" + // Home Position
"^PR6" + // Print Speed (~120mm/sec)
"^MD25" + // Darkness Level
"^PW541" + // Label Width (67.69mm for 203 DPI)
"^LL550" + // Reduced Label Length (fix gap)
"^PN0" + // No Extra Page Feed
"^PON" + // Disable Printer's Auto Feed Mode
"^XZ";
printer.sendCommand(settings);
// Convert BufferedImage to ZebraImage
ZebraImage zebraImage = new ZebraImage(bufferedImage);
// Print image
printer.printImage(zebraImage, 0, 0, 0, 0, false);
connection.close();
}
}

View File

@ -15,9 +15,11 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@Service
public class BundleService {
@ -54,6 +56,35 @@ public class BundleService {
return bundles;
}
/*
* find bundle by id
* */
public Bundle getBundlesById( long id){
return bundleDAO.find(id);
}
/*
* find bundle by barcode
* */
public List<Bundle> getBundles( String barcode){
List<Bundle> bundles = new ArrayList<>();
List<Bundle> fetchBundle = bundleDAO.findByBarcodeLike( barcode );
List<Long> ids = fetchBundle.stream()
.map(Bundle::getMasterBundleId)
.distinct()
.collect(Collectors.toList());
if(!ids.isEmpty()){
List<Long> masterBundles = masterBundleDAO.findByIdAndReceiveIsTrue(ids);
bundles = fetchBundle.stream()
.filter(e -> masterBundles.contains(e.getMasterBundleId())
&& e.getWrapQuantity().compareTo(
e.getProduction() != null ? e.getProduction() : BigDecimal.ZERO) != 0)
.collect(Collectors.toList());
}
return bundles;
}
/*
* find master bundles by params
* */
@ -109,7 +140,6 @@ public class BundleService {
return stitchingOfflineItems;
}
/*
*
* */

View File

@ -2,6 +2,7 @@ package com.utopiaindustries.service;
import com.utopiaindustries.dao.ctp.*;
import com.utopiaindustries.model.ctp.*;
import com.utopiaindustries.model.ctp.BundleWrapper;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;
@ -90,7 +91,7 @@ public class InventoryService {
for ( JobCardItem jobCardItem : items) {
// create + save bundles
List<Bundle> bundles = createBundles( jobCardItem, piecesMap.get( jobCardItem.getId( ) ) );
List<Bundle> bundles = createBundles( jobCardItem, piecesMap.get( jobCardItem.getId( ) ),jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) );
// create transactions
createTransactions( bundles, jobCardItem.getAccountId( ), InventoryArtifactType.BUNDLE.name( ));
jobCardItem.setActualProduction( jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) );
@ -155,10 +156,12 @@ public class InventoryService {
if ( transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.IN.name( ))) {
initialBalance = initialBalance.add( inventoryTransactionLeg.getQuantity( ));
}else if(transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.OUT.name( )) && inventoryTransactionLeg.getQuantity().equals(BigDecimal.ZERO)){
initialBalance = BigDecimal.ZERO;
} else {
initialBalance = initialBalance.subtract( inventoryTransactionLeg.getQuantity( ));
}else if(transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.OUT.name( ))) {
if (inventoryTransactionLeg.getQuantity().equals(BigDecimal.ZERO)) {
initialBalance = BigDecimal.ZERO;
} else {
initialBalance = initialBalance.subtract(inventoryTransactionLeg.getQuantity());
}
}
inventoryTransactionLeg.setBalance( initialBalance);
inventoryTransactionLeg.setId( inventoryTransactionLegDAO.save( inventoryTransactionLeg));
@ -179,18 +182,18 @@ public class InventoryService {
// create bundles from cut pieces
private List<Bundle> createBundles( JobCardItem jobCardItem,
List<CutPiece> jobCardItemPieces ) {
List<CutPiece> jobCardItemPieces, BigDecimal value ) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( );
if ( jobCardItemPieces != null && !jobCardItemPieces.isEmpty( )) {
if ( value != null && !value.equals(BigDecimal.ZERO)) {
List<Bundle> bundles = new ArrayList<>( );
// create bundle against every cut piece
for ( CutPiece cutPiece : jobCardItemPieces ) {
if(value.intValue()<=20){
Bundle bundle = new Bundle( );
bundle.setItemId( jobCardItem.getItemId( ));
bundle.setSku( jobCardItem.getSku( ));
bundle.setJobCardId( jobCardItem.getJobCardId( ) );
bundle.setWrapQuantity( cutPiece.getQuantity( ));
bundle.setType( cutPiece.getType( ));
bundle.setWrapQuantity(value);
bundle.setType( "BUNDLE");
bundle.setCreatedAt( LocalDateTime.now( ));
bundle.setCreatedBy( authentication.getName( ));
bundles.add( bundle);
@ -198,8 +201,32 @@ public class InventoryService {
bundle.setBarcode( cryptographyService.generateRandomString( 15));
// save again after barcode generation
bundle.setId( bundleDAO.save( bundle));
}
}else{
int quantity = value.intValue();
int batchSize = 20;
int iterations = (int) Math.ceil((double) quantity / batchSize);
for (int i = 0; i < iterations; i++) {
int start = i * batchSize + 1; // Start index
int end = Math.min((i + 1) * batchSize, quantity); // Last index
int perBundleQuantity = end - start + 1;
Bundle bundle = new Bundle( );
bundle.setItemId( jobCardItem.getItemId( ));
bundle.setSku( jobCardItem.getSku( ));
bundle.setJobCardId( jobCardItem.getJobCardId( ) );
bundle.setWrapQuantity( BigDecimal.valueOf(perBundleQuantity));
bundle.setType( "BUNDLE");
bundle.setCreatedAt( LocalDateTime.now( ));
bundle.setCreatedBy( authentication.getName( ));
bundles.add( bundle);
bundle.setId( bundleDAO.save( bundle));
bundle.setBarcode( cryptographyService.generateRandomString( 15));
// save again after barcode generation
bundle.setId( bundleDAO.save( bundle));
}
}
// for ( Map.Entry<JobCardItem, List<CutPiece>> entry : jobCardItemPieces ) {
// JobCardItem key = entry.getKey( );
// List<CutPiece> value = entry.getValue( );
@ -243,11 +270,13 @@ public class InventoryService {
long fromAccount = lastInvTransaction.getAccountId( );
createInventoryTransactionLeg( transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.BUNDLE.name( ));
// IN
createInventoryTransactionLeg( transaction, bundle, toAccount, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.BUNDLE.name( ));
bundle.setType("BUNDLE");
createInventoryTransactionLeg( transaction, bundle, toAccount, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.STITCH_BUNDLE.name( ));
}
}
// update status
masterBundle.setIsReceived( true);
masterBundle.setAccountId(toAccount);
masterBundleDAO.save( masterBundle);
}
}
@ -296,73 +325,69 @@ public class InventoryService {
* create finished items from master bundles
* */
@Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED )
public void createStitchingOfflineItemsFromJobCard( JobCard jobCard) {
List<JobCardItem> jobCardItems = jobCard.getItems( );
List<JobCardItem> updatedItems = new ArrayList<>( );
public void createStitchingOfflineItemsFromJobCard( BundleWrapper wrapper) {
List<JobCardItem> updatedItems = new ArrayList<>();
List<Bundle> updateBundles = new ArrayList<>();
JobCard jobCard = null;
// validate items
validateItems( jobCardItems);
// check whether all bundles are received against finish goods
checkAllBundleAreReceived( jobCard.getId( ), jobCardItems);
for ( JobCardItem item : jobCardItems) {
if(item.getTotalProduction() == null){
item.setTotalProduction(BigDecimal.ZERO);
}
item.setJobCardId(jobCard.getId());
// select which has inventory
if ( item.getProduction( ).compareTo( BigDecimal.ZERO ) != 0 ) {
// production is completed out bundles
if ( item.getActualProduction( ).compareTo( item.getTotalProduction( ).add( item.getProduction( ))) == 0) {
// create out transactions of bundles in master bundles
List<Bundle> bundles = bundleDAO.findByItemIdAndCardId( item.getItemId( ), jobCard.getId( ));
if ( bundles != null && !bundles.isEmpty( )) {
// bundle ids
List<Long> bundleIds = bundles.stream( ).map( Bundle::getId).collect( Collectors.toList( ));
//switching table transaction in Transaction Table
InventoryTransaction transaction = createInventoryTransaction("Against Movement from Stitching to Stitched Offline Item");
inventoryTransactionDAO.save(transaction);
Map<Long, InventoryTransactionLeg> lastBundleIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), bundleIds, InventoryArtifactType.BUNDLE.name( ))
.stream( )
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( )));
// create Transaction
InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Stitching to Stitched Offline Item");
inventoryTransactionDAO.save( transaction);
// create transaction legs
for ( Bundle bundle : bundles) {
InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( bundle.getId( ), null);
if ( lastInvTransaction != null) {
// OUT
long fromAccount = lastInvTransaction.getAccountId( );
createInventoryTransactionLeg( transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.BUNDLE.name( ));
}
}
//TransactionLeg Transaction
List<Long> bundleIds = wrapper.getBundles().stream().map(Bundle::getId).collect(Collectors.toList());
Map<Long, InventoryTransactionLeg> lastBundleIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), bundleIds, InventoryArtifactType.STITCH_BUNDLE.name())
.stream()
.collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
for (Bundle subBundle : wrapper.getBundles()) {
long accountId = masterBundleDAO.find(subBundle.getMasterBundleId()).getAccountId();
if(subBundle.getCurrentProduction().compareTo(BigDecimal.ZERO) != 0){
Bundle bundle = bundleDAO.find(subBundle.getId());
jobCard = jobCardDAO.find(subBundle.getJobCardId());
long production = (bundle.getProduction() == null) ? 0 : bundle.getProduction().longValue() ;
long wrapQuantity = bundle.getWrapQuantity().longValue();
JobCardItem jobCardItem = jobCardItemDAO.findByCardIdAndItemId(subBundle.getJobCardId(),subBundle.getItemId());
InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(subBundle.getId(), null);
if (lastInvTransaction != null ) {
if (wrapQuantity == production + subBundle.getCurrentProduction().longValue()) {
// OUT
long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg(transaction, subBundle, accountId, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCH_BUNDLE.name());
}
}
// create finished items
List<StitchingOfflineItem> stitchingOfflineItems = createStitchingOfflineItems( item);
// create stitchingOfflineItems items
List<StitchingOfflineItem> stitchingOfflineItems = createStitchingOfflineItems(subBundle.getCurrentProduction(),jobCardItem,subBundle.getId());
// create IN Transactions of Finished Items into account
createTransactions( stitchingOfflineItems, jobCard.getToAccountId( ), InventoryArtifactType.STITCHING_OFFLINE.name( ));
item.setTotalProduction( item.getTotalProduction( ).add( item.getProduction( )));
item.setJobCardId( jobCard.getId( ));
updatedItems.add( item);
createTransactions(stitchingOfflineItems, accountId, InventoryArtifactType.STITCHING_OFFLINE.name());
jobCardItem.setTotalProduction(jobCardItem.getTotalProduction().add(subBundle.getCurrentProduction()));
jobCardItem.setJobCardId(jobCard.getId());
updatedItems.add(jobCardItem);
BigDecimal pro = subBundle.getCurrentProduction();
bundle.setProduction(pro);
bundleDAO.save(bundle);
}
}
// save all
jobCardItemDAO.saveAll( updatedItems);
jobCardItemDAO.saveAll(updatedItems);
}
/*
* create finished items
* */
public List<StitchingOfflineItem> createStitchingOfflineItems( JobCardItem jobCardItem) {
public List<StitchingOfflineItem> createStitchingOfflineItems( BigDecimal totalItem, JobCardItem jobCardItem,long bundleId) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( );
List<StitchingOfflineItem> items = new ArrayList<>( );
if ( jobCardItem != null) {
for ( int i = 1; i <= jobCardItem.getProduction( ).intValue( ); i++) {
for ( int i = 1; i <= totalItem.intValue( ); i++) {
StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem( );
stitchingOfflineItem.setCreatedAt( LocalDateTime.now( ));
stitchingOfflineItem.setCreatedBy( authentication.getName( ));
stitchingOfflineItem.setItemId( jobCardItem.getItemId( ));
stitchingOfflineItem.setSku( jobCardItem.getSku( ));
stitchingOfflineItem.setBundleId(bundleId);
stitchingOfflineItem.setJobCardId( jobCardItem.getJobCardId( ));
stitchingOfflineItem.setIsQa( false );
long id = stitchingOfflineItemDAO.save( stitchingOfflineItem);

View File

@ -35,8 +35,10 @@ public class JobCardService {
private final UserInventoryAccountDAO userInventoryAccountDAO;
private final FinishedItemDAO finishedItemDAO;
private final StitchingOfflineItemDAO stitchingOfflineItemDAO;
private final SkuCutPiecesDAO skuCutPiecesDAO;
public JobCardService(JobCardDAO jobCardDAO, CutPieceTypeDAO cutPieceTypeDAO, JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, ItemDAO itemDAO, LocationSiteDAO locationSiteDAO, PurchaseOrderDAO purchaseOrderDAO, UserInventoryAccountDAO userInventoryAccountDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) {
public JobCardService(JobCardDAO jobCardDAO, CutPieceTypeDAO cutPieceTypeDAO, JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, ItemDAO itemDAO, LocationSiteDAO locationSiteDAO, PurchaseOrderDAO purchaseOrderDAO, UserInventoryAccountDAO userInventoryAccountDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO, SkuCutPiecesDAO skuCutPiecesDAO) {
this.skuCutPiecesDAO = skuCutPiecesDAO;
this.jobCardDAO = jobCardDAO;
this.cutPieceTypeDAO = cutPieceTypeDAO;
this.jobCardItemDAO = jobCardItemDAO;
@ -138,6 +140,13 @@ public class JobCardService {
long itemId = jobCardItemDAO.save(item);
for (CutPiece cutPiece : item.getCutPieces()) {
cutPiece.setJobCardItemId(itemId);
if (!skuCutPiecesDAO.doesExist(cutPiece.getType(), item.getSku())){
SkuCutPieces skuCutPieces = new SkuCutPieces();
skuCutPieces.setType(cutPiece.getType());
skuCutPieces.setSku(item.getSku());
//save cut-piece for sku next time fetch
skuCutPiecesDAO.save(skuCutPieces);
}
cutPieces.add(cutPiece);
}
}

View File

@ -32,5 +32,9 @@ spring:
ctp:
printer:
ipAdd: 172.16.53.32
port: 9100
ipAdd: 172.16.53.53
port: 9100
stitchQRPath: ./src/main/resources/static/sample_qr_output.pdf
bundleIpAdd: 172.16.53.22
bundlePort: 9100
bundlePath: ./src/main/resources/static/bundle.pdf

View File

@ -1,7 +1,7 @@
application:
title: Cut To Pack Service
version: v1.0
name: application-dev
name: application-prod
spring:
profiles:

View File

@ -84,6 +84,24 @@
onItemSelect(itemId, invItem) {
this.item.itemId = invItem.id;
this.item.sku = invItem.sku;
},
searchCutPieceBySku(sku) {
$.ajax({
url: `/ctp/rest/cut-pieces?sku=${sku}`,
method: 'GET',
success: (response) => {
this.$set(this.item, 'cutPieces', response);
},
error: (error) => {
console.error('Error fetching data:', error);
}
});
}
},
watch: {
'item.sku': function(newSku, oldSku) {
console.log('SKU changed:', newSku);
this.searchCutPieceBySku(newSku);
}
},
template: `
@ -161,8 +179,6 @@
</a>
</div>
</div>
</div>
`
});
@ -177,15 +193,16 @@
},
template: `
<div class="row mt-1">
<input hidden="hidden" v-bind:name="'items[' + pIndex + '].cutPieces[' + index +'].id'" v-bind:value="piece.id">
<input hidden="hidden" v-bind:name="'items[' + pIndex + '].cutPieces[' + index +'].jobCardItemId'" v-bind:value="piece.jobCardItemId">
<input hidden="hidden" v-bind:name="'items[' + pIndex + '].cutPieces[' + index + '].jobCardItemId'" v-bind:value="piece.jobCardItemId || 0">
<div class="col-md-5">
<select class="form-control" v-bind:name="'items[' + pIndex + '].cutPieces[' + index +'].type'" v-model="piece.type" required>
<option value="">Please Select</option>
<option v-for="(type,index) in $types"
v-bind:selected="type.title === piece.type"
v-bind:value="type.title">{{type.title}}</option>
</select>
<select class="form-control"
v-bind:name="'items[' + pIndex + '].cutPieces[' + index +'].type'"
v-model="piece.type" required>
<option value="">Please Select</option>
<option v-for="(title, index) in $types"
v-bind:selected="title.type === piece.type"
v-bind:value="title.type">{{ title.type }}</option>
</select>
</div>
<div class="col-md-5">
<input type="number" class="form-control" v-bind:name="'items[' + pIndex + '].cutPieces[' + index +'].quantity'" v-model="piece.quantity" required>
@ -195,10 +212,8 @@
</div>
</div>
`
});
let app = new Vue({
el: '#jobCardApp',
data: {

View File

@ -39,6 +39,7 @@
<input hidden="hidden" v-bind:name="'items[' + index + '].createdAt'" v-bind:value="getFormattedDateTime(item.createdAt)">
<input hidden="hidden" v-bind:name="'items[' + index + '].jobCardId'" v-bind:value="item.jobCardId">
<input hidden="hidden" v-bind:name="'items[' + index + '].barcode'" v-bind:value="item.barcode" >
<input hidden="hidden" v-bind:name="'items[' + index + '].bundleId'" v-bind:value="item.bundleId" >
<input hidden="hidden" v-bind:name="'items[' + index + '].isQa'" v-bind:value="item.isQa">
<span> {{item.id}} </span>
</td>

View File

@ -18,7 +18,7 @@
<item-search
v-bind:id-field-name="'items[' + index + '].itemId'"
v-bind:id="item.itemId"
v-bind:title="item.title"
v-bind:type="item.type"
v-bind:show-label="false"
v-bind:disabled="true"></item-search>
</td>
@ -37,7 +37,7 @@
<span class="form-control" readonly>{{item.expectedProduction}}</span>
</td>
<td width="200">
<input class="form-control" min="0" type="number" v-bind:name="'items[' + index + '].actualProduction'" v-bind:max="item.expectedProduction" required>
<input class="form-control" min="0" type="number" v-bind:name="'items[' + index + '].actualProduction'" required>
</td>
<td>
{{ populateCuttingAccount() }}
@ -64,12 +64,12 @@
<select style="width: 150px;" class="form-control" v-bind:name="'pieces[' + index +'].type'" v-model="piece.type" disabled>
<option value="">Please Select</option>
<option v-for="(type,index) in $types"
v-bind:selected="type.title === piece.type"
v-bind:value="type.title">{{type.title}}</option>
v-bind:selected="type.type === piece.type"
v-bind:value="type.type">{{type.type}}</option>
</select>
</div>
<div class="col-md-6" style="padding-left: 40px;">
<input class="form-control" type="number" v-bind:name="'items[' + pIndex + '].pieces[' + index +'].quantity'" v-model="piece.quantity" required/>
<input class="form-control" type="number" v-bind:name="'items[' + pIndex + '].pieces[' + index +'].quantity'" v-model="piece.quantity" min="0" required/>
</div>
</div>
`

View File

@ -11,7 +11,7 @@
onJobCardSelect : function( id, card ){
this.card = card;
$.ajax({
url: `/ctp/rest/job-cards/${id}/items`,
url: `/ctp/rest/job-cards/${id}`,
method: 'GET',
contentType: 'application/json',
dataType: 'json',
@ -23,8 +23,25 @@
}
});
},
onBundleSelects : function( id, card ){
this.card = card;
console.log(id);
console.log(card);
$.ajax({
url: `/ctp/rest/bundles/find-bundle-by-id/${id}`,
method: 'GET',
contentType: 'application/json',
dataType: 'json',
success: ( data ) =>{
console.log(data)
this.items.push(data);
},
error: function (err) {
console.log(err)
}
});
}
},
mounted : function () {
}

View File

@ -3367,6 +3367,49 @@ if ( typeof Vue !== 'undefined' ) {
});
/*
* bundle search
* */
Vue.component('bundle-search-by-barcode',{
mixins: [searchComponentMixin],
methods : {
getSearchUrl : function () {
let url = `/ctp/rest/bundles/find-bundle-by-barcode?term=${encodeURIComponent( this.list.term )}`
return url;
},
getEmittedEventName: function() {
return 'job-card-select';
},
getTitle: function( card ) {
return `(${card.barcode})`;
}
},
props: {
labelText: {
default: 'Search By Bundle'
},
titleFieldName: {
default: 'cardTitle'
},
idFieldName: {
default: 'jobCardId'
},
codeFieldName : {
default : 'jobCardCode'
},
filter : {
default : true
},
inputMode: {
default : 'none'
}
}
})
/*
* job card search
* */

View File

@ -29,9 +29,9 @@
<select name="type" class="form-control">
<option value="">Please select</option>
<option th:each="type: ${types}"
th:value="${type.title}"
th:text="${type.title}"
th:selected="${#strings.equals(param['type'], #strings.toString(type.title))}"
th:value="${type.type}"
th:text="${type.type}"
th:selected="${#strings.equals(param['type'], #strings.toString(type.type))}"
></option>
</select>
</div>

View File

@ -29,6 +29,7 @@
<th>Sku</th>
<th>Created By</th>
<th>Created At</th>
<th>Received</th>
<th>
<div class="mb-2">
<button class="btn btn-sm btn-outline-primary" type="submit">Generate
@ -51,6 +52,7 @@
<td th:text="*{sku}"></td>
<td th:text="*{createdBy}"></td>
<td ctp:formatdatetime="*{createdAt}"></td>
<td th:text="${bundle.isReceived ? 'YES' : 'NO'}"></td>
<td>
<div class="form-group form-check mb-0">
<input class="form-check-input" type="checkbox"

View File

@ -121,6 +121,7 @@
<td>
<span th:if="${cardStitchingItem.getQaStatus() == 'APPROVED'}" th:text="${cardStitchingItem.getQaStatus()}" class="badge badge-APPROVED font-sm"></span>
<span th:if="${cardStitchingItem.getQaStatus() == 'REJECT'}" th:text="${cardStitchingItem.getQaStatus()}" class="badge badge-warning font-sm"></span>
<span th:if="${cardStitchingItem.getQaStatus() == null}" th:text="NOT-PERFORMED" class="badge badge-danger font-sm"></span>
</td>
<td th:text="${cardStitchingItem.getQaRemarks()}"></td>
<td ctp:formatdatetime="${cardStitchingItem.getCreatedAt()}"></td>

View File

@ -13,26 +13,17 @@
<form th:action="@{/stitching/create-stitching-items}"
method="POST"
id="finishedItemApp"
th:object="${jobCard}">
th:object="${bundleWrapper}">
<div class="bg-light p-3 mb-3 col-sm-8">
<div class="form-row">
<div class="col-sm-5 p-0">
<job-card-search
<bundle-search-by-barcode
v-bind:id-field-name="'id'"
v-bind:filter="false"
v-bind:items="true"
v-on:job-card-select="onJobCardSelect">
</job-card-search>
</div>
<div class="col-sm-4">
<label>Stitching Account</label>
<select class="form-control" name="toAccountId" required>
<option value="">Please Select</option>
<option th:each="account :${accounts}"
th:value="${account.id}"
th:text="${account.title}"
th:title="${account.notes}"></option>
</select>
v-on:job-card-select="onBundleSelects">
</bundle-search-by-barcode>
</div>
</div>
</div>
@ -46,48 +37,48 @@
<th>Item ID</th>
<th>Sku</th>
<th>Expected Production</th>
<th>Actual Production</th>
<th>Current Production</th>
<th>Production</th>
</tr>
<tbody>
<tr v-if="(item.actualProduction !== item.totalProduction)" v-for="(item,index) in items">
<tr v-if="(item.wrapQuantity !== item.production)" v-for="(item,index) in items">
<td >
<div class="form-group form-check mb-0">
<input class="form-check-input" type="checkbox" v-bind:name="'items[' + index + '].isSelected'" v-model="item.isSelected">
<label th:for="*{id}" class="form-check-label"></label>
</div>
</td>
<td>
<input hidden="hidden" v-bind:name="'items[' + index + '].id'" v-bind:value="item.id">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].jobCardId'" v-bind:value="item.jobCardId">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].itemId'" v-bind:value="item.itemId">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].id'" v-bind:value="item.id">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].masterBundleId'" v-bind:value="item.masterBundleId">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].type'" v-bind:value="item.type">
<span class="form-control">{{item.id}}</span>
</td>
<td>
<input hidden="hidden" v-bind:name="'items[' + index + '].itemId'" v-bind:value="item.itemId">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].itemId'" v-bind:value="item.itemId">
<span class="form-control">{{item.itemId}}</span>
</td>
<td>
<input hidden="hidden" v-bind:name="'items[' + index + '].sku'" v-bind:value="item.sku">
<input hidden="hidden" v-bind:name="'bundles[' + index + '].sku'" v-bind:value="item.sku">
<span class="form-control">{{item.sku}}</span>
</td>
<td>
<input hidden="hidden" v-bind:name="'items[' + index + '].expectedProduction'" v-bind:value="item.expectedProduction">
<span class="form-control">{{item.expectedProduction}}</span>
<input hidden="hidden" v-bind:name="'bundles[' + index + '].wrapQuantity'" v-bind:value="item.wrapQuantity">
<span class="form-control">{{item.wrapQuantity}}</span>
</td>
<td>
<input hidden="hidden" v-bind:name="'items[' + index + '].actualProduction'" v-bind:value="item.actualProduction">
<span class="form-control">{{item.actualProduction}}</span>
<input hidden="hidden" v-bind:name="'bundles[' + index + '].production'" v-bind:value="item.production">
<span class="form-control">{{item.production}}</span>
</td>
<td>
<input hidden="hidden" v-bind:name="'items[' + index + '].totalProduction'" v-bind:value="item.totalProduction">
<span class="form-control">{{item.totalProduction}}</span>
</td>
<td>
<input class="form-control" v-bind:name="'items[' + index + '].production'"
<input class="form-control" v-bind:name="'bundles[' + index + '].currentProduction'"
type="number"
v-bind:value="item.production"
v-bind:value="item.currentProduction"
v-bind:min="0"
v-bind:max="item.actualProduction - item.totalProduction"
v-bind:max="item.wrapQuantity - item.production"
v-bind:readonly="!item.isSelected"
>
</td>