diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java index d4b3327..416d044 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java @@ -24,9 +24,10 @@ public class JobCardItemDAO { 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 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, is_complete) VALUES (:id, :job_card_id, :item_id, :sku, :expected_production, :actual_production, :total_production, :account_id, :length, :width, :gsm, :wt_ply, :ply, :is_complete) 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), is_complete =VALUES(is_complete) ", 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 account_id IN (:account_ids) AND is_complete = FALSE ", TABLE_NAME ); + private final String SELECT_ALL_ACTIVE_ITEM = String.format("SELECT CASE WHEN MIN(is_complete) = TRUE THEN TRUE ELSE FALSE END FROM %s WHERE job_card_id = :job_card_id AND id IN (:id)", TABLE_NAME); public JobCardItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; @@ -47,7 +48,9 @@ public class JobCardItemDAO { .addValue("width", jobCardItem.getWidth() ) .addValue("gsm", jobCardItem.getGsm() ) .addValue("wt_ply", jobCardItem.getWtPly() ) - .addValue("ply", jobCardItem.getPly() ); + .addValue("ply", jobCardItem.getPly() ) + .addValue("is_complete", jobCardItem.isComplete() ); + return params; } @@ -112,12 +115,20 @@ public class JobCardItemDAO { return namedParameterJdbcTemplate.query( SELECT_BY_IDS, params, new JobCardItemRowMapper() ); } - public List findByJobCardAndAccountIdsAndIsReceived( Long jobCardId, Long actualProduction, List accountIds ){ + public List findByJobCardAndAccountIdsAndIsReceived( Long jobCardId, List accountIds ){ if( accountIds == null || accountIds.isEmpty() ) return new ArrayList<>(); MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue( "account_ids", accountIds ); params.addValue("job_card_id", jobCardId ); - params.addValue("actual_production", actualProduction ); return namedParameterJdbcTemplate.query( SELECT_BY_JOB_CARD_AND_ACCOUNT_IDS , params, new JobCardItemRowMapper() ); } + + public boolean checkAllItemsComplete( Long jobCardId, List itemsId ){ + if( itemsId == null || itemsId.isEmpty() ) return false; + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue( "id", itemsId ); + params.addValue("job_card_id", jobCardId ); + Boolean allComplete = namedParameterJdbcTemplate.queryForObject(SELECT_ALL_ACTIVE_ITEM, params, Boolean.class); + return Boolean.TRUE.equals(allComplete); + } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java b/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java index 23d9585..fd0b155 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java +++ b/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java @@ -23,6 +23,7 @@ public class JobCardItem { private List cutPieces; private String title; private boolean isSelected; + private boolean isComplete; public JobCardItem() { this.expectedProduction = BigDecimal.ZERO; @@ -167,6 +168,14 @@ public class JobCardItem { isSelected = selected; } + public boolean isComplete() { + return isComplete; + } + + public void setComplete(boolean complete) { + isComplete = complete; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java index af83ec6..512f2ac 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java +++ b/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java @@ -9,6 +9,8 @@ public class JobCardItemWrapper { private long jobCardItemId; private List pieces; private BigDecimal actualProduction; + private int perBundleQuantity; + private boolean finalReceived; public long getJobCardId() { return jobCardId; @@ -42,6 +44,22 @@ public class JobCardItemWrapper { this.actualProduction = actualProduction; } + public int getPerBundleQuantity() { + return perBundleQuantity; + } + + public void setPerBundleQuantity(int perBundleQuantity) { + this.perBundleQuantity = perBundleQuantity; + } + + public boolean getFinalReceived() { + return finalReceived; + } + + public void setFinalReceived(boolean finalReceived) { + this.finalReceived = finalReceived; + } + @Override public String toString() { return "JobCardItemWrapper{" + diff --git a/src/main/java/com/utopiaindustries/service/InventoryService.java b/src/main/java/com/utopiaindustries/service/InventoryService.java index e0402a5..a397ba5 100644 --- a/src/main/java/com/utopiaindustries/service/InventoryService.java +++ b/src/main/java/com/utopiaindustries/service/InventoryService.java @@ -73,6 +73,7 @@ public class InventoryService { .collect( Collectors.toMap( JobCardItemWrapper::getJobCardItemId, JobCardItemWrapper::getActualProduction ) ); List items = jobCardItemDAO.findByIds( jobCardItemWrapperIds ); + if ( items != null && !items.isEmpty( ) ) { // get job card item ids List jobCardItemIds = items.stream( ) @@ -90,16 +91,38 @@ public class InventoryService { .collect( Collectors.groupingBy( CutPiece::getJobCardItemId)); for ( JobCardItem jobCardItem : items) { - // create + save bundles - List bundles = createBundles( jobCardItem, piecesMap.get( jobCardItem.getId( ) ),jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) ); + + int quantity = jobCardItemWrappers.stream() + .filter(e -> e.getJobCardItemId() == jobCardItem.getId()) + .mapToInt(JobCardItemWrapper::getPerBundleQuantity) + .findFirst() + .orElse(0); + + boolean cuttingComplete = jobCardItemWrappers.stream() + .filter(e -> e.getJobCardItemId() == jobCardItem.getId()) + .map(JobCardItemWrapper::getFinalReceived) + .findFirst() + .orElse(false); + + BigDecimal production = jobCardItemWrappers.stream() + .filter(e -> e.getJobCardItemId() == jobCardItem.getId()) + .map(JobCardItemWrapper::getActualProduction) + .findFirst() + .orElse(BigDecimal.ZERO); + + List bundles = createBundles( jobCardItem,quantity,jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) ); // create transactions createTransactions( bundles, jobCardItem.getAccountId( ), InventoryArtifactType.BUNDLE.name( )); - jobCardItem.setActualProduction( jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) ); + jobCardItem.setActualProduction( jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ), BigDecimal.ZERO ).add(jobCardItem.getActualProduction()) ); + jobCardItem.setComplete(cuttingComplete); + } // update items with quantity jobCardItemDAO.saveAll( items ); // update job card inv status - updateJobCardInventoryStatus( jobCard ); + if(jobCardItemDAO.checkAllItemsComplete(jobCardId,jobCardItemIds)) { + updateJobCardInventoryStatus(jobCard); + } } else { throw new RuntimeException( "Items Not found in Job Card"); } @@ -182,29 +205,12 @@ public class InventoryService { // create bundles from cut pieces private List createBundles( JobCardItem jobCardItem, - List jobCardItemPieces, BigDecimal value ) { + int perBundleWrap, BigDecimal value ) { Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); if ( value != null && !value.equals(BigDecimal.ZERO)) { List bundles = new ArrayList<>( ); - // create bundle against every cut piece - if(value.intValue()<=20){ - Bundle bundle = new Bundle( ); - bundle.setItemId( jobCardItem.getItemId( )); - bundle.setSku( jobCardItem.getSku( )); - bundle.setJobCardId( jobCardItem.getJobCardId( ) ); - bundle.setWrapQuantity(value); - 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)); - }else{ int quantity = value.intValue(); - int batchSize = 20; - + int batchSize = perBundleWrap; int iterations = (int) Math.ceil((double) quantity / batchSize); for (int i = 0; i < iterations; i++) { @@ -224,8 +230,6 @@ public class InventoryService { bundle.setBarcode( cryptographyService.generateRandomString( 15)); // save again after barcode generation bundle.setId( bundleDAO.save( bundle)); - } - } // for ( Map.Entry> entry : jobCardItemPieces ) { // JobCardItem key = entry.getKey( ); diff --git a/src/main/java/com/utopiaindustries/service/JobCardService.java b/src/main/java/com/utopiaindustries/service/JobCardService.java index 05b488d..b28c3e4 100644 --- a/src/main/java/com/utopiaindustries/service/JobCardService.java +++ b/src/main/java/com/utopiaindustries/service/JobCardService.java @@ -184,7 +184,7 @@ public class JobCardService { .collect( Collectors.toList() ); // get items has account ids and has actual production not filled - List items = jobCardItemDAO.findByJobCardAndAccountIdsAndIsReceived( id, 0L ,accountIds ); + List items = jobCardItemDAO.findByJobCardAndAccountIdsAndIsReceived( id ,accountIds ); if (items != null && !items.isEmpty()) { // get job card ite ids List jobCardItemIds = items.stream() diff --git a/src/main/resources/static/js/finishing/finished-item-segregation-form.js b/src/main/resources/static/js/finishing/finished-item-segregation-form.js index 56af686..32c39ec 100644 --- a/src/main/resources/static/js/finishing/finished-item-segregation-form.js +++ b/src/main/resources/static/js/finishing/finished-item-segregation-form.js @@ -90,6 +90,7 @@ }, methods : { onItemSelect: function (id, item) { + console.log("wdwawdwwadwwdwda",item.id) this.items.push(item); }, removeItem: function (index) { diff --git a/src/main/resources/static/js/receive-inventory.js b/src/main/resources/static/js/receive-inventory.js index 6009347..c0ec570 100644 --- a/src/main/resources/static/js/receive-inventory.js +++ b/src/main/resources/static/js/receive-inventory.js @@ -4,23 +4,27 @@ Vue.prototype.$accounts = window.ctp.accounts; Vue.component('item-rows', { + data() { + return { + wrapQuantity: 0 + }; + }, props: ['index', 'item'], methods : { populateCuttingAccount : function (){ return this.$accounts.find(account => account.id === this.item.accountId).title; }, + handleValueChange : function(value){ + this.wrapQuantity = value + } + }, template: ` - - - - + + + + {{item.id}} {{item.sku}} @@ -36,8 +40,17 @@ {{item.expectedProduction}} + + {{item.actualProduction}} + - + + + + + + + {{ populateCuttingAccount() }} @@ -84,12 +97,15 @@ - + + - + + + diff --git a/src/main/resources/static/js/vue-components.js b/src/main/resources/static/js/vue-components.js index 49e62aa..7adb546 100644 --- a/src/main/resources/static/js/vue-components.js +++ b/src/main/resources/static/js/vue-components.js @@ -216,6 +216,7 @@ if ( typeof Vue !== 'undefined' ) { v-bind:disabled="disabled" v-bind:readonly="readOnly" v-bind:inputmode="inputMode" + autofocus v-bind:class="{ 'is-invalid': ( showInputErrorOnZeroId && ( entityId === 0 || entityId == null ) ) }" autocomplete="off"> @@ -3525,43 +3526,75 @@ if ( typeof Vue !== 'undefined' ) { }); - /* - * finished item search - * */ - Vue.component('finished-item-search',{ - mixins: [searchComponentMixin], - methods : { - getSearchUrl : function () { - return `/ctp/rest/finished-items/search?term=${encodeURIComponent( this.list.term )}&is-segregated=${this.isSegregated}` - }, - getEmittedEventName: function() { - return 'finished-item-select'; - }, - getTitle: function( item ) { - return `${item.id} - ( ${item.barcode} )`; - } +Vue.component('search-item', { + props: { + label: { + type: String, + default: 'Search Finished Item' }, - props: { - labelText: { - default: 'Search Finished Item' - }, - titleFieldName: { - default: 'title' - }, - idFieldName: { - default: 'id' - }, - codeFieldName : { - default : 'code' - }, - isSegregated : { - default : false - }, - inputMode: { - default : 'none' + url: { + type: String, + default: '' + }, + isSegregated: { + type: Boolean, + default: false + }, + debounceTime: { + type: Number, + default: 500 + } + }, + data() { + return { + searchTerm: '', + timeout: null + }; + }, + methods: { + handleInput() { + clearTimeout(this.timeout); + this.timeout = setTimeout(() => { + this.fetchData(); + }, this.debounceTime); + }, + async fetchData() { + if (this.searchTerm.trim() === '') return; + try { + const response = await fetch(`${this.url}?term=${encodeURIComponent(this.searchTerm)}&is-segregated=${this.isSegregated}`); + const data = await response.json(); + + if (data.length > 0) { + const selectedItem = data[0]; + this.$emit('finished-item-select', selectedItem.id, selectedItem); + this.searchTerm = `${selectedItem.id} - (${selectedItem.barcode})`; + setTimeout(() => { + this.searchTerm = ''; + }, 500); + } else { + setTimeout(() => { + this.searchTerm = ''; + }, 500); + } + } catch (error) { + console.error('Error fetching search results:', error); } } - }) + }, + + template: ` +
+ + +
+ ` +}); /* * bundle search component diff --git a/src/main/resources/templates/cutting/generate-master-barcode.html b/src/main/resources/templates/cutting/generate-master-barcode.html index 026b0c2..9af5cae 100644 --- a/src/main/resources/templates/cutting/generate-master-barcode.html +++ b/src/main/resources/templates/cutting/generate-master-barcode.html @@ -17,9 +17,11 @@
- + +
diff --git a/src/main/resources/templates/cutting/receive-inventory.html b/src/main/resources/templates/cutting/receive-inventory.html index f4f1b48..5a04b0a 100644 --- a/src/main/resources/templates/cutting/receive-inventory.html +++ b/src/main/resources/templates/cutting/receive-inventory.html @@ -22,6 +22,7 @@ v-on:job-card-select="onCardSelect" v-bind:required="true" > + diff --git a/src/main/resources/templates/finishing/segregate-inventory.html b/src/main/resources/templates/finishing/segregate-inventory.html index fa964ac..fc6bcad 100644 --- a/src/main/resources/templates/finishing/segregate-inventory.html +++ b/src/main/resources/templates/finishing/segregate-inventory.html @@ -14,11 +14,10 @@
- - + +
diff --git a/src/main/resources/templates/quality-control/qc-items-form.html b/src/main/resources/templates/quality-control/qc-items-form.html index 38a0249..006bd8d 100644 --- a/src/main/resources/templates/quality-control/qc-items-form.html +++ b/src/main/resources/templates/quality-control/qc-items-form.html @@ -13,12 +13,13 @@
-
Search Stitched Item
- + +
ItemID Item Sku/Title Cut Pieces Expected ProductionCurrent Production Actual ProductionAccountPer Bundle QuantityCutting CompleteAccount