Compare commits

..

No commits in common. "a22979f8cafc8aa97bc03a0d3625d619b6584331" and "0d61494a3f77426a1654ed572cc8a22db6ae7d06" have entirely different histories.

31 changed files with 248 additions and 585 deletions

View File

@ -55,12 +55,6 @@
<groupId>org.thymeleaf.extras</groupId> <groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId> <artifactId>thymeleaf-extras-java8time</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.30</version>
<scope>compile</scope>
</dependency>
<dependency> <dependency>
<groupId>org.thymeleaf.extras</groupId> <groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-springsecurity5</artifactId> <artifactId>thymeleaf-extras-springsecurity5</artifactId>

View File

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

View File

@ -21,14 +21,13 @@ public class BundleDAO {
private final String SELECT_QUERY = String.format( "SELECT * FROM %s WHERE id = :id", TABLE_NAME ); 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 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 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, 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 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 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_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_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_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_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_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_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) { public BundleDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
@ -41,7 +40,6 @@ public class BundleDAO {
params.addValue( "id", bundle.getId() ) params.addValue( "id", bundle.getId() )
.addValue( "item_id", bundle.getItemId() ) .addValue( "item_id", bundle.getItemId() )
.addValue( "sku", bundle.getSku() ) .addValue( "sku", bundle.getSku() )
.addValue("production",bundle.getProduction())
.addValue( "wrap_quantity", bundle.getWrapQuantity() ) .addValue( "wrap_quantity", bundle.getWrapQuantity() )
.addValue( "barcode", bundle.getBarcode() ) .addValue( "barcode", bundle.getBarcode() )
.addValue( "type", bundle.getType() ) .addValue( "type", bundle.getType() )
@ -63,12 +61,6 @@ 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 // find all
public List<Bundle> findAll() { public List<Bundle> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new BundleRowMapper() ); return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new BundleRowMapper() );

View File

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

View File

@ -1,7 +1,6 @@
package com.utopiaindustries.dao.ctp; package com.utopiaindustries.dao.ctp;
import com.utopiaindustries.model.ctp.JobCardItem; import com.utopiaindustries.model.ctp.JobCardItem;
import com.utopiaindustries.model.ctp.MasterBundle;
import com.utopiaindustries.util.KeyHolderFunctions; import com.utopiaindustries.util.KeyHolderFunctions;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
@ -23,7 +22,6 @@ public class JobCardItemDAO {
private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id DESC", 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 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 = 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 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_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 ); 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 );
@ -97,15 +95,6 @@ public class JobCardItemDAO {
return namedParameterJdbcTemplate.query(SELECT_BY_CARD_ID, params, new JobCardItemRowMapper() ); 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 ){ public List<JobCardItem> findByIds( List<Long> ids ){
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "ids", ids ); params.addValue( "ids", ids );

View File

@ -20,12 +20,10 @@ public class MasterBundleDAO {
private final String SELECT_QUERY = String.format( "SELECT * FROM %s WHERE id = :id", TABLE_NAME ); 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 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 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, 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 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 SELECT_BY_LIMIT = String.format( "SELECT * FROM %s ORDER BY id DESC LIMIT :limit", 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_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 = 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) { public MasterBundleDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
@ -39,7 +37,6 @@ public class MasterBundleDAO {
.addValue( "barcode", masterBundle.getBarcode() ) .addValue( "barcode", masterBundle.getBarcode() )
.addValue( "item_id", masterBundle.getItemId() ) .addValue( "item_id", masterBundle.getItemId() )
.addValue( "sku", masterBundle.getSku() ) .addValue( "sku", masterBundle.getSku() )
.addValue( "account_id", masterBundle.getAccountId() )
.addValue( "created_by", masterBundle.getCreatedBy() ) .addValue( "created_by", masterBundle.getCreatedBy() )
.addValue( "created_at", masterBundle.getCreatedAt() ) .addValue( "created_at", masterBundle.getCreatedAt() )
.addValue( "job_card_id", masterBundle.getJobCardId() ) .addValue( "job_card_id", masterBundle.getJobCardId() )
@ -57,13 +54,6 @@ public class MasterBundleDAO {
.orElse( new MasterBundle() ); .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 // find all
public List<MasterBundle> findAll() { public List<MasterBundle> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new MasterBundleRowMapper() ); return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new MasterBundleRowMapper() );

View File

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

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_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 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 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,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 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 SELECT_BY_LIMIT = String.format("SELECT * FROM %s ORDER BY id DESC LIMIT :limit", 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 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 ); private final String SELECT_BY_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", TABLE_NAME );
@ -40,7 +40,6 @@ public class StitchingOfflineItemDAO {
.addValue( "item_id", stitchingOfflineItem.getItemId() ) .addValue( "item_id", stitchingOfflineItem.getItemId() )
.addValue( "sku", stitchingOfflineItem.getSku() ) .addValue( "sku", stitchingOfflineItem.getSku() )
.addValue( "barcode", stitchingOfflineItem.getBarcode() ) .addValue( "barcode", stitchingOfflineItem.getBarcode() )
.addValue("bundle_id",stitchingOfflineItem.getBundleId())
.addValue( "created_at", stitchingOfflineItem.getCreatedAt() ) .addValue( "created_at", stitchingOfflineItem.getCreatedAt() )
.addValue( "created_by", stitchingOfflineItem.getCreatedBy() ) .addValue( "created_by", stitchingOfflineItem.getCreatedBy() )
.addValue("job_card_id", stitchingOfflineItem.getJobCardId() ) .addValue("job_card_id", stitchingOfflineItem.getJobCardId() )

View File

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

View File

@ -22,7 +22,7 @@ public class SummaryInventoryReportDao {
+ "(:sku IS NULL OR sku = :sku) " + "(:sku IS NULL OR sku = :sku) "
+ "AND (:item_id IS NULL OR item_id = :item_id) " + "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) " + "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), account_id, sku, parent_document_type, parent_document_piece_type " + "GROUP BY DATE(transaction_leg_datetime), sku, parent_document_type, parent_document_piece_type "
+ "ORDER BY transaction_date, sku;"; + "ORDER BY transaction_date, sku;";
public SummaryInventoryReportDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { public SummaryInventoryReportDao(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {

View File

@ -6,8 +6,9 @@ public enum BarcodeStickerSize {
SIZE_2_X_3( 3 * 72, 2 * 72, 10, 10, 6, 6, 50, 50, 125, 125, 14, 9, 7), 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_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_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, 200, 10, 40, 6, 50, 40, 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( 67.69f, 125.73f ,10 , 10, 20, 6, 60, 60, 125, 125, 4, 9, 7); SIZE_1_X_2( 94f, 49f , 20, 10, 48, 6, 42, 42, 125, 125, 4, 9, 7);
private final float width; private final float width;
private final float height; private final float height;

View File

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

View File

@ -1,16 +0,0 @@
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

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,6 @@ package com.utopiaindustries.model.ctp;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
public class StitchingOfflineItem implements InventoryArtifact { public class StitchingOfflineItem implements InventoryArtifact {
@ -18,7 +17,6 @@ public class StitchingOfflineItem implements InventoryArtifact {
private boolean isQa; private boolean isQa;
private String qaRemarks; private String qaRemarks;
private String qaStatus; private String qaStatus;
private long bundleId;
@Override @Override
public String getType() { public String getType() {
@ -109,22 +107,6 @@ public class StitchingOfflineItem implements InventoryArtifact {
this.qaStatus = qaStatus; 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 @Override
public String toString() { public String toString() {
return "StitchingOfflineItem{" + return "StitchingOfflineItem{" +

View File

@ -34,13 +34,4 @@ public class BundleRestController {
return bundleService.findBundlesByMasterId( masterId ); 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,12 +1,6 @@
package com.utopiaindustries.service; package com.utopiaindustries.service;
import com.google.zxing.BarcodeFormat; import com.google.zxing.BarcodeFormat;
import com.itextpdf.kernel.colors.ColorConstants;
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.TextAlignment;
import com.utopiaindustries.dao.ctp.*; import com.utopiaindustries.dao.ctp.*;
import com.utopiaindustries.model.ctp.*; import com.utopiaindustries.model.ctp.*;
import com.utopiaindustries.util.BarcodeUtils; import com.utopiaindustries.util.BarcodeUtils;
@ -16,27 +10,18 @@ import com.zebra.sdk.comm.TcpConnection;
import com.zebra.sdk.graphics.internal.ZebraImage; import com.zebra.sdk.graphics.internal.ZebraImage;
import com.zebra.sdk.printer.ZebraPrinter; import com.zebra.sdk.printer.ZebraPrinter;
import com.zebra.sdk.printer.ZebraPrinterFactory; 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.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; 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.nio.file.Path;
import java.nio.file.FileSystems;
import javax.imageio.ImageIO;
import java.awt.*; import java.awt.*;
import java.awt.Font; import java.awt.Font;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;
import java.io.*; import java.io.*;
import java.time.format.DateTimeFormatter; import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.zxing.EncodeHintType; import com.google.zxing.EncodeHintType;
@ -63,17 +48,13 @@ public class BarcodeService {
private final MasterBundleDAO masterBundleDAO; private final MasterBundleDAO masterBundleDAO;
private final FinishedItemDAO finishedItemDAO; private final FinishedItemDAO finishedItemDAO;
private final StitchingOfflineItemDAO stitchingOfflineItemDAO; private final StitchingOfflineItemDAO stitchingOfflineItemDAO;
private final InventoryAccountDAO inventoryAccountDAO;
private final JobCardItemDAO jobCardItemDAO;
public BarcodeService(BundleDAO bundleDAO, JobCardDAO jobCardDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO, InventoryAccountDAO inventoryAccountDAO, JobCardItemDAO jobCardItemDAO) { public BarcodeService(BundleDAO bundleDAO, JobCardDAO jobCardDAO, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) {
this.bundleDAO = bundleDAO; this.bundleDAO = bundleDAO;
this.jobCardDAO = jobCardDAO; this.jobCardDAO = jobCardDAO;
this.masterBundleDAO = masterBundleDAO; this.masterBundleDAO = masterBundleDAO;
this.finishedItemDAO = finishedItemDAO; this.finishedItemDAO = finishedItemDAO;
this.stitchingOfflineItemDAO = stitchingOfflineItemDAO; this.stitchingOfflineItemDAO = stitchingOfflineItemDAO;
this.inventoryAccountDAO = inventoryAccountDAO;
this.jobCardItemDAO = jobCardItemDAO;
} }
/* /*
@ -99,168 +80,134 @@ public class BarcodeService {
} }
public void getBarcodeImages(List<? extends InventoryArtifact> artifacts, public void getBarcodeImages(List<? extends InventoryArtifact> artifacts,
BarcodeStickerSize stickerSize, BarcodeStickerSize stickerSize,
String artifactType) throws Exception { 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
for (int page = 0; page < totalPages; page++) { for (InventoryArtifact artifact : artifacts) {
// Create a Blank A4 Page Image // Create a blank BufferedImage (an image with the size of the sticker)
BufferedImage a4Image = new BufferedImage(pageWidth, pageHeight, BufferedImage.TYPE_INT_ARGB); BufferedImage stickerImage = new BufferedImage((int) stickerSize.getWidth()*2, (int) stickerSize.getHeight()*2, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = a4Image.createGraphics(); Graphics2D g2d = stickerImage.createGraphics();
g2d.scale(2,2);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
// Set background color (white for the sticker)
g2d.setColor(Color.WHITE); g2d.setColor(Color.WHITE);
g2d.fillRect(0, 0, pageWidth, pageHeight); 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.setColor(Color.BLACK); g2d.setColor(Color.BLACK);
g2d.drawString(sku, x, stickerSize.getMarginTop() + fontMetrics.getAscent()+20);
Font barcodeFont = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+8); // Create the barcode image
Font detailFont = new Font("Helvetica", Font.PLAIN, stickerSize.getTextSize()+3); byte[] imgBytes = BarcodeUtils.getBarcodeImageByteArray(artifact.getBarcode(), BarcodeFormat.CODE_128, stickerSize.getImageWidthBarcode()+500, stickerSize.getImageHeightBarcode()+30);
BufferedImage barcodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
for (int i = 0; i < totalStickersPerPage; i++) { // Draw the barcode image on the sticker
int artifactIndex = page * totalStickersPerPage + i; int barcodeX =(int) (stickerSize.getWidth() - barcodeImage.getWidth()) / 2;
if (artifactIndex >= artifacts.size()) break; int barcodeY = stickerSize.getMarginTop() + fontMetrics.getAscent() + 30; // Add some margin
InventoryArtifact artifact = artifacts.get(artifactIndex); g2d.drawImage(barcodeImage, barcodeX, barcodeY, null);
int row = i / cols;
int col = i % cols;
int x = col * (pageWidth / cols); // Add the barcode value below the barcode image
int y = row * (pageHeight / rows); g2d.drawString(artifact.getBarcode(), (stickerSize.getWidth() - fontMetrics.stringWidth(artifact.getBarcode())) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent());
Font stickerFont = new Font("Helvetica", Font.BOLD, stickerSize.getTextSize() + 10); // If artifactType is Bundle, add additional info
g2d.setFont(stickerFont); if (artifactType.equalsIgnoreCase(Bundle.class.getSimpleName())) {
// Draw Sticker Border String typeText = String.format("%s : %d", artifact.getType(), artifact.getId());
g2d.drawRect(x, y, pageWidth / cols, pageHeight / rows); g2d.drawString(typeText, (stickerSize.getWidth() - fontMetrics.stringWidth(typeText)) / 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); 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,
// Draw SKU barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 77);
g2d.setFont(barcodeFont); } else {
String sku = artifact.getSku(); // Add first character of artifact type
FontMetrics fontMetrics = g2d.getFontMetrics(); String type = String.valueOf(artifactType.charAt(0));
int textWidth = fontMetrics.stringWidth(sku); g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()+10));
g2d.drawString(sku, x + ((pageWidth / cols) - textWidth) / 2, y + fontMetrics.getAscent()+ stickerSize.getMarginTop()+10); g2d.drawString(type, (stickerSize.getWidth() - fontMetrics.stringWidth(type)) / 2,
barcodeY + barcodeImage.getHeight() + fontMetrics.getAscent() + 45);
// 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 // Finalize drawing
g2d.dispose(); g2d.dispose();
Path path = FileSystems.getDefault().getPath("./src/main/resources/static/barcode_a4_" + (page + 1) + ".png"); printLabel(stickerImage);
File outputFile = path.toFile();
ImageIO.write(a4Image, "PNG", outputFile);
} }
} }
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, public void getBarcodeImagesForStitchItems(List<? extends InventoryArtifact> artifacts,
BarcodeStickerSize stickerSize, BarcodeStickerSize stickerSize,
String artifactType) throws Exception { String artifactType) throws Exception {
Path pdfPath = FileSystems.getDefault().getPath("./src/main/resources/static/sample_qr_output.pdf");
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) { for (InventoryArtifact artifact : artifacts) {
JobCard jobCard = jobCardDAO.find(artifact.getJobCardId()); JobCard jobCard = jobCardDAO.find(artifact.getJobCardId());
List<Bundle> 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();
PdfPage page = pdfDoc.addNewPage(); BufferedImage stickerImage = new BufferedImage(stickerWidth * 2, stickerHeight * 2, BufferedImage.TYPE_INT_ARGB);
PdfCanvas canvas = new PdfCanvas(page); Graphics2D g2d = stickerImage.createGraphics();
canvas.setFillColor(ColorConstants.WHITE); g2d.scale(2, 2);
canvas.rectangle(0, 0, stickerSize.getWidth(), stickerSize.getHeight()); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
canvas.fill();
// Draw QR Code on Left Side** 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()); byte[] imgBytes = generateQRCodeImageByteArray(artifact.getBarcode(), stickerSize.getImageWidthBarcode(), stickerSize.getImageHeightBarcode());
Image qrCodeImage = new Image(ImageDataFactory.create(imgBytes)); BufferedImage qrCodeImage = ImageIO.read(new ByteArrayInputStream(imgBytes));
float qrY =stickerSize.getMarginLeft()+50 ; int centerXQR = stickerSize.getMarginLeft()-12;
float qrX = stickerSize.getMarginTop(); int centerYQR = (stickerHeight / 2) + (textHeightId / 2)+1;
AffineTransform originalTransformQR = g2d.getTransform();
qrCodeImage.setFixedPosition(qrX - 16, qrY-47); g2d.rotate(Math.toRadians(-90), centerXID, centerYID);
document.add(qrCodeImage); g2d.drawImage(qrCodeImage, centerXQR, centerYQR, null);
g2d.setTransform(originalTransformQR);
float textX = stickerSize.getMarginLeft() + 40;
float textY = stickerSize.getMarginTop() +40;
// Prepare Text Lines Below QR Code
String sku = artifact.getSku(); String sku = artifact.getSku();
String jobCardCode = jobCard.getCode(); String jobCardCode = jobCard.getCode();
String combinedText = sku + " \\ " + jobCardCode + " \\ " + artifact.getBundleId(); String combinedText = sku + " \\" + jobCardCode + concatenatedIds;
int maxLength = 14; int maxLength = 16; // Max characters per line
List<String> lines = new ArrayList<>(); List<String> lines = new ArrayList<>();
for (int i = 0; i < 3; i++) { for (int i = 0; i < 3; i++) {
int start = i * maxLength; int start = i * maxLength;
if (start < combinedText.length()) { if (start < combinedText.length()) {
@ -268,76 +215,47 @@ public class BarcodeService {
lines.add(part); lines.add(part);
} }
} }
g2d.rotate(Math.toRadians(-90), stickerWidth / 2, stickerHeight / 2);
float textY1 = textY-30; // Draw Rotated Text Below QR Code
for (String line : lines) { g2d.setColor(Color.BLACK);
Paragraph rotatedText = new Paragraph(line) g2d.setFont(new Font("Helvetica", Font.BOLD, stickerSize.getTextSize()));
.setFontColor(ColorConstants.BLACK) FontMetrics fontMetrics = g2d.getFontMetrics();
.setFontSize((float) (stickerSize.getTextSize()+2)) int lineHeight = fontMetrics.getHeight();
.setTextAlignment(TextAlignment.LEFT) int centerXSKU = stickerSize.getMarginLeft()+4;
.setFixedPosition( textX-48, textY1-18, 220); int centerYSKU = (stickerHeight / 2) + (textHeightId / 4)+20;
document.add(rotatedText); AffineTransform originalTransformSKu = g2d.getTransform();
textY1 -= 6; 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));
} }
String id = String.valueOf(artifact.getId()); g2d.setTransform(originalTransformSKu);
document.add(new Paragraph(id)
.setFontColor(ColorConstants.BLACK)
.setFontSize(stickerSize.getTextSize()+6)
.setTextAlignment(TextAlignment.LEFT)
.setFixedPosition(textX-21, textY + 10, 140));
float dottedLine = textY - 60; g2d.dispose();
for(int i= 0 ;i<16;i++){
document.add(new Paragraph("|")
.setFontSize(stickerSize.getTextSize())
.setFontColor(ColorConstants.BLACK)
.setBold()
.setRotationAngle(-Math.PI / 2) // ✅ -90 Degree Rotate
.setTextAlignment(TextAlignment.LEFT)
.setFixedPosition(dottedLine,textX+40, 100));
dottedLine += 7; // Save Image
} Path path = FileSystems.getDefault().getPath("./src/main/resources/static/sample_qr.png");
File outputFile = path.toFile();
float dottedLine2 = textY - 60; ImageIO.write(stickerImage, "PNG", outputFile);
for(int i= 0 ;i<16;i++){
document.add(new Paragraph("|")
.setFontSize(stickerSize.getTextSize())
.setFontColor(ColorConstants.BLACK)
.setBold()
.setRotationAngle(-Math.PI / 2) // ✅ -90 Degree Rotate
.setTextAlignment(TextAlignment.LEFT)
.setFixedPosition(dottedLine2,textX+75, 100));
dottedLine2 += 7;
}
if (artifact != artifacts.get(artifacts.size() - 1)) {
document.add(new AreaBreak());
}
} }
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) { public byte[] generateQRCodeImageByteArray(String data, int width, int height) {
try { try {
QRCodeWriter qrCodeWriter = new QRCodeWriter(); QRCodeWriter qrCodeWriter = new QRCodeWriter();
// QR Code generation settings
Map<EncodeHintType, Object> hintMap = new HashMap<>(); Map<EncodeHintType, Object> hintMap = new HashMap<>();
hintMap.put(EncodeHintType.MARGIN, 1); // Optional: control margin size hintMap.put(EncodeHintType.MARGIN, 1); // Optional: control margin size
// Generate QR code matrix
BitMatrix bitMatrix = qrCodeWriter.encode(data, BarcodeFormat.QR_CODE, width, height, hintMap); 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); BufferedImage qrImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
qrImage.createGraphics().fillRect(0, 0, width, height); qrImage.createGraphics().fillRect(0, 0, width, height);

View File

@ -15,11 +15,9 @@ import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Collectors;
@Service @Service
public class BundleService { public class BundleService {
@ -56,35 +54,6 @@ public class BundleService {
return bundles; 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 * find master bundles by params
* */ * */
@ -140,6 +109,7 @@ public class BundleService {
return stitchingOfflineItems; return stitchingOfflineItems;
} }
/* /*
* *
* */ * */

View File

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

View File

@ -193,6 +193,7 @@
}, },
template: ` template: `
<div class="row mt-1"> <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 || 0"> <input hidden="hidden" v-bind:name="'items[' + pIndex + '].cutPieces[' + index + '].jobCardItemId'" v-bind:value="piece.jobCardItemId || 0">
<div class="col-md-5"> <div class="col-md-5">
<select class="form-control" <select class="form-control"

View File

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

View File

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

View File

@ -11,7 +11,7 @@
onJobCardSelect : function( id, card ){ onJobCardSelect : function( id, card ){
this.card = card; this.card = card;
$.ajax({ $.ajax({
url: `/ctp/rest/job-cards/${id}`, url: `/ctp/rest/job-cards/${id}/items`,
method: 'GET', method: 'GET',
contentType: 'application/json', contentType: 'application/json',
dataType: 'json', dataType: 'json',
@ -23,25 +23,8 @@
} }
}); });
},
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 () { mounted : function () {
} }

View File

@ -3367,49 +3367,6 @@ 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 * job card search
* */ * */

View File

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

View File

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

View File

@ -121,7 +121,6 @@
<td> <td>
<span th:if="${cardStitchingItem.getQaStatus() == 'APPROVED'}" th:text="${cardStitchingItem.getQaStatus()}" class="badge badge-APPROVED font-sm"></span> <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() == '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>
<td th:text="${cardStitchingItem.getQaRemarks()}"></td> <td th:text="${cardStitchingItem.getQaRemarks()}"></td>
<td ctp:formatdatetime="${cardStitchingItem.getCreatedAt()}"></td> <td ctp:formatdatetime="${cardStitchingItem.getCreatedAt()}"></td>

View File

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