diff --git a/src/main/java/com/utopiaindustries/auth/AdminRole.java b/src/main/java/com/utopiaindustries/auth/AdminRole.java index 313dd9b..ddc2f71 100644 --- a/src/main/java/com/utopiaindustries/auth/AdminRole.java +++ b/src/main/java/com/utopiaindustries/auth/AdminRole.java @@ -9,6 +9,6 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.METHOD, ElementType.TYPE}) -@PreAuthorize( "hasAnyRole('ROLE_ADMIN')") +@PreAuthorize("hasAnyRole('ROLE_ADMIN')") public @interface AdminRole { } diff --git a/src/main/java/com/utopiaindustries/controller/FinishingController.java b/src/main/java/com/utopiaindustries/controller/FinishingController.java index ef2c030..0e5391a 100644 --- a/src/main/java/com/utopiaindustries/controller/FinishingController.java +++ b/src/main/java/com/utopiaindustries/controller/FinishingController.java @@ -19,7 +19,7 @@ import java.util.List; @Controller @FinishingRole -@RequestMapping( "/finishing" ) +@RequestMapping("/finishing") public class FinishingController { private final FinishedItemDAO finishedItemDAO; @@ -37,26 +37,26 @@ public class FinishingController { } @GetMapping - public String showHome(Model model ){ + public String showHome(Model model) { return "redirect:/finishing/finished-items"; } - @GetMapping( "/finished-items" ) - public String showFinishedItems( @RequestParam(value = "id", required = false ) String id, - @RequestParam(value = "item-id", required = false ) String itemId, - @RequestParam( value = "sku", required = false ) String sku, - @RequestParam( value = "start-date", required = false) String startDate, - @RequestParam( value = "end-date", required = false ) String endDate, - @RequestParam( value = "job-card-id", required = false ) String jobCardId, - @RequestParam( value = "count", required = false ) Long count, - Model model ){ + @GetMapping("/finished-items") + public String showFinishedItems(@RequestParam(value = "id", required = false) String id, + @RequestParam(value = "item-id", required = false) String itemId, + @RequestParam(value = "sku", required = false) String sku, + @RequestParam(value = "start-date", required = false) String startDate, + @RequestParam(value = "end-date", required = false) String endDate, + @RequestParam(value = "job-card-id", required = false) String jobCardId, + @RequestParam(value = "count", required = false) Long count, + Model model) { LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(30) : LocalDate.parse(startDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); model.addAttribute("startDate", startDate1); model.addAttribute("endDate", endDate1); - List itemList = bundleService.getFinishedItem( id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId ,count ); - model.addAttribute("items", itemList ) ; + List itemList = bundleService.getFinishedItem(id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId, count); + model.addAttribute("items", itemList); return "finishing/finished-item-list"; } @@ -65,39 +65,38 @@ public class FinishingController { /* * get finishing inventory accounts * */ - @GetMapping( "/inventory-accounts" ) - public String getInventoryAccounts( @RequestParam( value = "id", required = false ) String id, - @RequestParam( value = "title", required = false) String title, - @RequestParam( value = "active", required = false ) String active, - @RequestParam( value = "created-by", required = false ) String createdBy, - @RequestParam( value = "start-date", required = false ) String startDate, - @RequestParam( value = "end-date", required = false ) String endDate, - @RequestParam( value = "site-id", required = false ) String siteId, - @RequestParam( value = "count", required = false, defaultValue = "100") Long count, - Model model ) { + @GetMapping("/inventory-accounts") + public String getInventoryAccounts(@RequestParam(value = "id", required = false) String id, + @RequestParam(value = "title", required = false) String title, + @RequestParam(value = "active", required = false) String active, + @RequestParam(value = "created-by", required = false) String createdBy, + @RequestParam(value = "start-date", required = false) String startDate, + @RequestParam(value = "end-date", required = false) String endDate, + @RequestParam(value = "site-id", required = false) String siteId, + @RequestParam(value = "count", required = false, defaultValue = "100") Long count, + Model model) { // 5 for Finishing - model.addAttribute("accounts", inventoryAccountService.getInventoryAccounts( id, title, active, createdBy, startDate, endDate, siteId, count, "PROCESS", "5" , false )); - model.addAttribute("locations", locationService.findAll() ); + model.addAttribute("accounts", inventoryAccountService.getInventoryAccounts(id, title, active, createdBy, startDate, endDate, siteId, count, "PROCESS", "5", false)); + model.addAttribute("locations", locationService.findAll()); return "/finishing/inventory-accounts"; } - @GetMapping( "segregate-inventory" ) - public String segregateFinishedItems( Model model ){ - model.addAttribute("accounts", inventoryAccountService.findInventoryAccountsForFinishedItems() ); - model.addAttribute("wrapper", new FinishedItemWrapper() ); + @GetMapping("segregate-inventory") + public String segregateFinishedItems(Model model) { + model.addAttribute("wrapper", new FinishedItemWrapper()); return "/finishing/segregate-inventory"; } - @PostMapping( "segregate-inventory" ) - public String segregateFinishItemsInventory( @ModelAttribute FinishedItemWrapper wrapper, - RedirectAttributes redirectAttributes, - Model model ){ + @PostMapping("segregate-inventory") + public String segregateFinishItemsInventory(@ModelAttribute FinishedItemWrapper wrapper, + RedirectAttributes redirectAttributes, + Model model) { try { - inventoryService.segregateFinishedItems( wrapper ); - redirectAttributes.addFlashAttribute("success", "Items Successfully saved !" ); - } catch ( Exception e ){ - redirectAttributes.addFlashAttribute("error", e.getMessage() ); + inventoryService.segregateFinishedItems(wrapper, wrapper.getQaStatus()); + redirectAttributes.addFlashAttribute("success", "Items Successfully saved !"); + } catch (Exception e) { + redirectAttributes.addFlashAttribute("error", e.getMessage()); } return "redirect:/finishing/segregate-inventory"; } diff --git a/src/main/java/com/utopiaindustries/controller/QualityControlController.java b/src/main/java/com/utopiaindustries/controller/QualityControlController.java index 4b666ac..2d90a97 100644 --- a/src/main/java/com/utopiaindustries/controller/QualityControlController.java +++ b/src/main/java/com/utopiaindustries/controller/QualityControlController.java @@ -18,7 +18,7 @@ import java.util.List; @Controller @QCRole -@RequestMapping( "/quality-control" ) +@RequestMapping("/quality-control") public class QualityControlController { private final InventoryAccountService inventoryAccountService; @@ -34,63 +34,63 @@ public class QualityControlController { } @GetMapping - public String homePage( Model model ){ + public String homePage(Model model) { return "redirect:/quality-control/qc-finished-items"; } /* * get stitching inventory accounts * */ - @GetMapping( "/inventory-accounts" ) - public String getInventoryAccounts( @RequestParam( value = "id", required = false ) String id, - @RequestParam( value = "title", required = false) String title, - @RequestParam( value = "active", required = false ) String active, - @RequestParam( value = "created-by", required = false ) String createdBy, - @RequestParam( value = "start-date", required = false ) String startDate, - @RequestParam( value = "end-date", required = false ) String endDate, - @RequestParam( value = "site-id", required = false ) String siteId, - @RequestParam( value = "count", required = false ) Long count, - Model model ) { + @GetMapping("/inventory-accounts") + public String getInventoryAccounts(@RequestParam(value = "id", required = false) String id, + @RequestParam(value = "title", required = false) String title, + @RequestParam(value = "active", required = false) String active, + @RequestParam(value = "created-by", required = false) String createdBy, + @RequestParam(value = "start-date", required = false) String startDate, + @RequestParam(value = "end-date", required = false) String endDate, + @RequestParam(value = "site-id", required = false) String siteId, + @RequestParam(value = "count", required = false) Long count, + Model model) { // 24 for Packaging model.addAttribute("accounts", inventoryAccountService.getInventoryAccounts(id, title, active, createdBy, startDate, endDate, siteId, count, "PROCESS", "4", false)); - model.addAttribute("locations", locationService.findAll() ); + model.addAttribute("locations", locationService.findAll()); return "/quality-control/inventory-accounts"; } - @GetMapping( "/qc-finished-items" ) - public String getFinishedItems( @RequestParam(value = "id", required = false ) String id, - @RequestParam(value = "item-id", required = false ) String itemId, - @RequestParam( value = "sku", required = false ) String sku, - @RequestParam( value = "start-date", required = false) String startDate, - @RequestParam( value = "end-date", required = false ) String endDate, - @RequestParam( value = "job-card-id", required = false ) String jobCardId, - @RequestParam( value = "count", required = false, defaultValue = "100") Long count, - Model model ){ + @GetMapping("/qc-finished-items") + public String getFinishedItems(@RequestParam(value = "id", required = false) String id, + @RequestParam(value = "item-id", required = false) String itemId, + @RequestParam(value = "sku", required = false) String sku, + @RequestParam(value = "start-date", required = false) String startDate, + @RequestParam(value = "end-date", required = false) String endDate, + @RequestParam(value = "job-card-id", required = false) String jobCardId, + @RequestParam(value = "count", required = false, defaultValue = "100") Long count, + Model model) { LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(30) : LocalDate.parse(startDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); model.addAttribute("startDate", startDate1); model.addAttribute("endDate", endDate1); - List itemList = bundleService.getFinishedItem( id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId ,count ); - model.addAttribute("items", itemList ) ; + List itemList = bundleService.getFinishedItem(id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId, count); + model.addAttribute("items", itemList); return "/quality-control/qc-items-list"; } - @GetMapping( "/qc-finished-item" ) - public String getAddFinishedItemForQCForm( Model model ){ + @GetMapping("/qc-finished-item") + public String getAddFinishedItemForQCForm(Model model) { // 4 for packaging - model.addAttribute("accounts", inventoryAccountService.findInventoryAccounts(5L) ); - model.addAttribute("wrapper", new StitchedItemWrapper() ); + model.addAttribute("accounts", inventoryAccountService.findInventoryAccounts(5L)); + model.addAttribute("wrapper", new StitchedItemWrapper()); return "/quality-control/qc-items-form"; } - @PostMapping( "/qc-finished-item" ) - public String postFinishedItemsAfterQc( @ModelAttribute StitchedItemWrapper wrapper, - RedirectAttributes redirectAttributes ){ + @PostMapping("/qc-finished-item") + public String postFinishedItemsAfterQc(@ModelAttribute StitchedItemWrapper wrapper, + RedirectAttributes redirectAttributes) { try { - inventoryService.createFinishedItemsAgainstStitchedItems( wrapper ); - redirectAttributes.addFlashAttribute("success", " Finished Items Are Generated Against Stitched Items" ); - }catch ( Exception ex ){ - redirectAttributes.addFlashAttribute("error", ex.getMessage() ); + inventoryService.createFinishedItemsAgainstStitchedItems(wrapper, wrapper.getQaStatus()); + redirectAttributes.addFlashAttribute("success", " Finished Items Are Generated Against Stitched Items"); + } catch (Exception ex) { + redirectAttributes.addFlashAttribute("error", ex.getMessage()); } return "redirect:/quality-control/qc-finished-item"; } diff --git a/src/main/java/com/utopiaindustries/dao/ctp/FinishedItemDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/FinishedItemDAO.java index 68f39ab..81a022c 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/FinishedItemDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/FinishedItemDAO.java @@ -17,182 +17,182 @@ import java.util.List; @Repository public class FinishedItemDAO { - private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; + private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; - private final String TABLE_NAME = "cut_to_pack.finished_item"; - 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_QUERY_BY_BARCODE_QA_STATUS = String.format( "SELECT case when EXISTS ( SELECT * FROM %s WHERE barcode = :barcode AND (qa_status = 'APPROVED' OR qa_status = 'WASHED') ) then true else false End as Result", TABLE_NAME ); - private final String SELECT_QUERY_BY_JOB_CARD = String.format( "SELECT * FROM %s WHERE job_card_id = :job_card_id", TABLE_NAME ); - private final String DELETE_QUERY = String.format( "DELETE FROM %s WHERE id = :id", TABLE_NAME ); - private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, item_id, sku, barcode, created_at, created_by, job_card_id, is_qa, stitched_item_id, is_segregated, qa_status, is_packed) VALUES (:id, :item_id, :sku, :barcode, :created_at, :created_by, :job_card_id, :is_qa, :stitched_item_id, :is_segregated, :qa_status, :is_packed) 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), stitched_item_id = VALUES(stitched_item_id), is_segregated = VALUES(is_segregated), qa_status = VALUES(qa_status), is_packed = VALUES(is_packed)", 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_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", 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_TERM = String.format( "SELECT * FROM %s WHERE barcode LIKE :term AND is_segregated = :is_segregated ORDER BY ID DESC", TABLE_NAME ); - private final String SELECT_BY_TERM_FOR_PACKAGING = String.format( "SELECT * FROM %s WHERE barcode LIKE :term AND is_segregated = :is_segregated AND qa_status = 'APPROVED' AND is_packed = FALSE ORDER BY ID DESC", TABLE_NAME ); - private final String SELECT_BY_STITCHED_ITEM_ID = String.format( "SELECT * FROM %s WHERE stitched_item_id = :stitched_item_id", TABLE_NAME ); - private final String SELECT_BY_STITCHED_ITEM_IDS = String.format( "SELECT * FROM %s WHERE stitched_item_id IN (:stitched_item_ids)", TABLE_NAME ); - private final String COUNT_TOTAL_FINISH_ITEM= String.format("SELECT COUNT(*) FROM %s WHERE job_card_id = :job_card_id AND is_segregated IS TRUE ",TABLE_NAME); - private final String SELECT_BY_JOB_CARD_AND_DATE = String.format( "SELECT * FROM %s WHERE job_card_id = :job_card_id AND (:start_date IS NULL OR :end_date IS NULL OR created_at BETWEEN :start_date AND :end_date)", TABLE_NAME ); + private final String TABLE_NAME = "cut_to_pack.finished_item"; + 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_QUERY_BY_BARCODE_QA_STATUS = String.format("SELECT case when EXISTS ( SELECT * FROM %s WHERE barcode = :barcode AND (qa_status = 'APPROVED' OR qa_status = 'WASHED') ) then true else false End as Result", TABLE_NAME); + private final String SELECT_QUERY_BY_JOB_CARD = String.format("SELECT * FROM %s WHERE job_card_id = :job_card_id", TABLE_NAME); + private final String DELETE_QUERY = String.format("DELETE FROM %s WHERE id = :id", TABLE_NAME); + private final String INSERT_QUERY = String.format("INSERT INTO %s (id, item_id, sku, barcode, created_at, created_by, job_card_id, is_qa, stitched_item_id, is_segregated, qa_status, is_packed) VALUES (:id, :item_id, :sku, :barcode, :created_at, :created_by, :job_card_id, :is_qa, :stitched_item_id, :is_segregated, :qa_status, :is_packed) 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), stitched_item_id = VALUES(stitched_item_id), is_segregated = VALUES(is_segregated), qa_status = VALUES(qa_status), is_packed = VALUES(is_packed)", 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_IDS = String.format("SELECT * FROM %s WHERE id IN (:ids)", 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_TERM = String.format("SELECT * FROM %s WHERE barcode LIKE :term AND is_qa = :is_qa AND is_packed = FALSE ORDER BY ID DESC", TABLE_NAME); + private final String SELECT_BY_TERM_FOR_PACKAGING = String.format("SELECT * FROM %s WHERE barcode LIKE :term AND is_segregated = :is_segregated AND qa_status = 'APPROVED' AND is_packed = FALSE ORDER BY ID DESC", TABLE_NAME); + private final String SELECT_BY_STITCHED_ITEM_ID = String.format("SELECT * FROM %s WHERE stitched_item_id = :stitched_item_id AND is_packed = FALSE", TABLE_NAME); + private final String SELECT_BY_STITCHED_ITEM_IDS = String.format("SELECT * FROM %s WHERE stitched_item_id IN (:stitched_item_ids)", TABLE_NAME); + private final String COUNT_TOTAL_FINISH_ITEM = String.format("SELECT COUNT(*) FROM %s WHERE job_card_id = :job_card_id AND is_segregated IS TRUE ", TABLE_NAME); + private final String SELECT_BY_JOB_CARD_AND_DATE = String.format("SELECT * FROM %s WHERE job_card_id = :job_card_id AND (:start_date IS NULL OR :end_date IS NULL OR created_at BETWEEN :start_date AND :end_date)", TABLE_NAME); - public FinishedItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { - this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; - } + public FinishedItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { + this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; + } - // prepare query params - private MapSqlParameterSource prepareInsertQueryParams( FinishedItem finishedItem ) { - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue( "id", finishedItem.getId() ) - .addValue( "item_id", finishedItem.getItemId() ) - .addValue( "sku", finishedItem.getSku() ) - .addValue( "barcode", finishedItem.getBarcode() ) - .addValue( "created_at", finishedItem.getCreatedAt() ) - .addValue( "created_by", finishedItem.getCreatedBy() ) - .addValue("job_card_id", finishedItem.getJobCardId() ) - .addValue("is_qa", finishedItem.getIsQa() ) - .addValue("stitched_item_id", finishedItem.getStitchedItemId() ) - .addValue("is_segregated", finishedItem.getIsSegregated() ) - .addValue("qa_status", finishedItem.getQaStatus() ) - .addValue("is_packed",finishedItem.isPackaging()); - return params; - } + // prepare query params + private MapSqlParameterSource prepareInsertQueryParams(FinishedItem finishedItem) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("id", finishedItem.getId()) + .addValue("item_id", finishedItem.getItemId()) + .addValue("sku", finishedItem.getSku()) + .addValue("barcode", finishedItem.getBarcode()) + .addValue("created_at", finishedItem.getCreatedAt()) + .addValue("created_by", finishedItem.getCreatedBy()) + .addValue("job_card_id", finishedItem.getJobCardId()) + .addValue("is_qa", finishedItem.getIsQa()) + .addValue("stitched_item_id", finishedItem.getStitchedItemId()) + .addValue("is_segregated", finishedItem.getIsSegregated()) + .addValue("qa_status", finishedItem.getQaStatus()) + .addValue("is_packed", finishedItem.isPackaging()); + return params; + } - // find - public FinishedItem find( long id ) { - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue( "id", id ); - return namedParameterJdbcTemplate.query( SELECT_QUERY, params, new FinishedItemRowMapper() ) - .stream() - .findFirst() - .orElse( new FinishedItem() ); - } + // find + public FinishedItem find(long id) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("id", id); + return namedParameterJdbcTemplate.query(SELECT_QUERY, params, new FinishedItemRowMapper()) + .stream() + .findFirst() + .orElse(new FinishedItem()); + } - // find all - public List findAll() { - return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new FinishedItemRowMapper() ); - } + // find all + public List findAll() { + return namedParameterJdbcTemplate.query(SELECT_ALL_QUERY, new FinishedItemRowMapper()); + } - // save - public long save( FinishedItem finishedItem ) { - KeyHolder keyHolder = new GeneratedKeyHolder(); - MapSqlParameterSource params = prepareInsertQueryParams( finishedItem ); - namedParameterJdbcTemplate.update( INSERT_QUERY, params, keyHolder ); - return KeyHolderFunctions.getKey( finishedItem.getId(), keyHolder ); - } + // save + public long save(FinishedItem finishedItem) { + KeyHolder keyHolder = new GeneratedKeyHolder(); + MapSqlParameterSource params = prepareInsertQueryParams(finishedItem); + namedParameterJdbcTemplate.update(INSERT_QUERY, params, keyHolder); + return KeyHolderFunctions.getKey(finishedItem.getId(), keyHolder); + } - // save all - public int[] saveAll( List finishedItems ) { - List batchArgs = new ArrayList<>(); - for ( FinishedItem finishedItem: finishedItems ) { - MapSqlParameterSource params = prepareInsertQueryParams( finishedItem ); - batchArgs.add( params ); - } - return namedParameterJdbcTemplate.batchUpdate( INSERT_QUERY, batchArgs.toArray(new MapSqlParameterSource[finishedItems.size()]) ); - } + // save all + public int[] saveAll(List finishedItems) { + List batchArgs = new ArrayList<>(); + for (FinishedItem finishedItem : finishedItems) { + MapSqlParameterSource params = prepareInsertQueryParams(finishedItem); + batchArgs.add(params); + } + return namedParameterJdbcTemplate.batchUpdate(INSERT_QUERY, batchArgs.toArray(new MapSqlParameterSource[finishedItems.size()])); + } - // delete - public boolean delete( long id ) { - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue( "id", id ); - return namedParameterJdbcTemplate.update( DELETE_QUERY, params ) > 0; - } + // delete + public boolean delete(long id) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("id", id); + return namedParameterJdbcTemplate.update(DELETE_QUERY, params) > 0; + } - public List findByLimit(Long count ){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue( "limit",count ); - return namedParameterJdbcTemplate.query( SELECT_BY_LIMIT , params, new FinishedItemRowMapper() ); - } + public List findByLimit(Long count) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("limit", count); + return namedParameterJdbcTemplate.query(SELECT_BY_LIMIT, params, new FinishedItemRowMapper()); + } - public List findByQuery(String query ){ - return namedParameterJdbcTemplate.query( query, new FinishedItemRowMapper() ); - } + public List findByQuery(String query) { + return namedParameterJdbcTemplate.query(query, new FinishedItemRowMapper()); + } - public List findByIds(List ids ){ - if( ids == null || ids.isEmpty() ) return new ArrayList<>(); - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("ids", ids ); - return namedParameterJdbcTemplate.query( SELECT_BY_IDS , params, new FinishedItemRowMapper() ); - } + public List findByIds(List ids) { + if (ids == null || ids.isEmpty()) return new ArrayList<>(); + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("ids", ids); + return namedParameterJdbcTemplate.query(SELECT_BY_IDS, params, new FinishedItemRowMapper()); + } - public List findByTerm( String term , boolean isSegregated ){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("term", "%" + term + "%" ); - params.addValue("is_segregated", isSegregated ); - return namedParameterJdbcTemplate.query( SELECT_BY_TERM , params, new FinishedItemRowMapper() ); - } + public List findByTerm(String term, boolean isQa) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("term", "%" + term + "%"); + params.addValue("is_qa", isQa); + return namedParameterJdbcTemplate.query(SELECT_BY_TERM, params, new FinishedItemRowMapper()); + } - public List findByTermForPackaging( String term , boolean isSegregated ){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("term", "%" + term + "%" ); - params.addValue("is_segregated", isSegregated ); - return namedParameterJdbcTemplate.query( SELECT_BY_TERM_FOR_PACKAGING , params, new FinishedItemRowMapper() ); - } + public List findByTermForPackaging(String term, boolean isSegregated) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("term", "%" + term + "%"); + params.addValue("is_segregated", isSegregated); + return namedParameterJdbcTemplate.query(SELECT_BY_TERM_FOR_PACKAGING, params, new FinishedItemRowMapper()); + } - // find By job card Id - public List findByJobCardId(long jobCardId ) { - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue( "job_card_id", jobCardId ); - return namedParameterJdbcTemplate.query(SELECT_QUERY_BY_JOB_CARD, params, new FinishedItemRowMapper() ); - } + // find By job card Id + public List findByJobCardId(long jobCardId) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("job_card_id", jobCardId); + return namedParameterJdbcTemplate.query(SELECT_QUERY_BY_JOB_CARD, params, new FinishedItemRowMapper()); + } - public FinishedItem findByStitchedItem( long stitchedItemId ){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("stitched_item_id", stitchedItemId ); - return namedParameterJdbcTemplate.query( SELECT_BY_STITCHED_ITEM_ID , params, new FinishedItemRowMapper() ) - .stream() - .findFirst() - .orElse( null ); + public FinishedItem findByStitchedItem(long stitchedItemId) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("stitched_item_id", stitchedItemId); + return namedParameterJdbcTemplate.query(SELECT_BY_STITCHED_ITEM_ID, params, new FinishedItemRowMapper()) + .stream() + .findFirst() + .orElse(null); - } + } - public HashMap findTotalFinishedItems(List itemIds, long jobCardId) { - HashMap totalCounts = new HashMap<>(); - MapSqlParameterSource params = new MapSqlParameterSource(); - for (long id : itemIds) { - params.addValue("job_card_id", jobCardId); - params.addValue("item_id", id); - Long total = namedParameterJdbcTemplate.queryForObject(FIND_TOTAL_COUNT, params, Long.class); - if (total != null) { - totalCounts.put(id, total); - } - } - return totalCounts; - } + public HashMap findTotalFinishedItems(List itemIds, long jobCardId) { + HashMap totalCounts = new HashMap<>(); + MapSqlParameterSource params = new MapSqlParameterSource(); + for (long id : itemIds) { + params.addValue("job_card_id", jobCardId); + params.addValue("item_id", id); + Long total = namedParameterJdbcTemplate.queryForObject(FIND_TOTAL_COUNT, params, Long.class); + if (total != null) { + totalCounts.put(id, total); + } + } + return totalCounts; + } - public List findByStitchedItemIds( List stitchedItemIds ){ - if( stitchedItemIds == null || stitchedItemIds.isEmpty() ) return new ArrayList<>(); - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("stitched_item_ids", stitchedItemIds ); - return namedParameterJdbcTemplate.query( SELECT_BY_STITCHED_ITEM_IDS, params, new FinishedItemRowMapper() ); - } + public List findByStitchedItemIds(List stitchedItemIds) { + if (stitchedItemIds == null || stitchedItemIds.isEmpty()) return new ArrayList<>(); + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("stitched_item_ids", stitchedItemIds); + return namedParameterJdbcTemplate.query(SELECT_BY_STITCHED_ITEM_IDS, params, new FinishedItemRowMapper()); + } - public List findByBarcodeAndApprovedStatus( List stitchingOfflineItems ){ - List items = new ArrayList<>(); - for (StitchingOfflineItem item : stitchingOfflineItems){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("barcode", item.getBarcode() ); - boolean check =Boolean.TRUE.equals(namedParameterJdbcTemplate.queryForObject( SELECT_QUERY_BY_BARCODE_QA_STATUS, params, Boolean.class )); - if(!check){ - items.add(item); - } - } - return items; - } + public List findByBarcodeAndApprovedStatus(List stitchingOfflineItems) { + List items = new ArrayList<>(); + for (StitchingOfflineItem item : stitchingOfflineItems) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("barcode", item.getBarcode()); + boolean check = Boolean.TRUE.equals(namedParameterJdbcTemplate.queryForObject(SELECT_QUERY_BY_BARCODE_QA_STATUS, params, Boolean.class)); + if (!check) { + items.add(item); + } + } + return items; + } - public Long calculateTotalFinishItem( long jobCardId ){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("job_card_id", jobCardId ); - Long count = namedParameterJdbcTemplate.queryForObject(COUNT_TOTAL_FINISH_ITEM, params, Long.class); - return count != null ? count : 0; - } + public Long calculateTotalFinishItem(long jobCardId) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("job_card_id", jobCardId); + Long count = namedParameterJdbcTemplate.queryForObject(COUNT_TOTAL_FINISH_ITEM, params, Long.class); + return count != null ? count : 0; + } - public List calculateTotalFinishItem( long jobCardId, String startDate, String endDate ){ - MapSqlParameterSource params = new MapSqlParameterSource(); - params.addValue("job_card_id", jobCardId ); - params.addValue( "start_date", startDate ); - params.addValue( "end_date", endDate ); - return namedParameterJdbcTemplate.query( SELECT_BY_JOB_CARD_AND_DATE, params, new FinishedItemRowMapper() ); - } + public List calculateTotalFinishItem(long jobCardId, String startDate, String endDate) { + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("job_card_id", jobCardId); + params.addValue("start_date", startDate); + params.addValue("end_date", endDate); + return namedParameterJdbcTemplate.query(SELECT_BY_JOB_CARD_AND_DATE, params, new FinishedItemRowMapper()); + } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/model/ctp/FinishedItemWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/FinishedItemWrapper.java index 755ca33..fb2ce16 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/FinishedItemWrapper.java +++ b/src/main/java/com/utopiaindustries/model/ctp/FinishedItemWrapper.java @@ -4,6 +4,8 @@ import java.util.List; public class FinishedItemWrapper { + private String qaStatus; + private List items; public List getItems() { @@ -14,6 +16,14 @@ public class FinishedItemWrapper { this.items = items; } + public String getQaStatus() { + return qaStatus; + } + + public void setQaStatus(String qaStatus) { + this.qaStatus = qaStatus; + } + @Override public String toString() { return "FinishedItemWrapper{" + diff --git a/src/main/java/com/utopiaindustries/model/ctp/StitchedItemWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/StitchedItemWrapper.java index 8c61503..affcf6c 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/StitchedItemWrapper.java +++ b/src/main/java/com/utopiaindustries/model/ctp/StitchedItemWrapper.java @@ -1,12 +1,20 @@ package com.utopiaindustries.model.ctp; import java.util.*; + public class StitchedItemWrapper { - + private String qaStatus; private List items; private Long finishedAccountId; + public String getQaStatus() { + return qaStatus; + } + + public void setQaStatus(String qaStatus) { + this.qaStatus = qaStatus; + } public List getItems() { return items; diff --git a/src/main/java/com/utopiaindustries/restcontroller/FinishedItemRestController.java b/src/main/java/com/utopiaindustries/restcontroller/FinishedItemRestController.java index 38e37bf..f1ff130 100644 --- a/src/main/java/com/utopiaindustries/restcontroller/FinishedItemRestController.java +++ b/src/main/java/com/utopiaindustries/restcontroller/FinishedItemRestController.java @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController; import java.util.List; @RestController -@RequestMapping( "/rest/finished-items" ) +@RequestMapping("/rest/finished-items") public class FinishedItemRestController { private final FinishedItemDAO finishedItemDAO; @@ -19,14 +19,15 @@ public class FinishedItemRestController { this.finishedItemDAO = finishedItemDAO; } - @GetMapping( "/search" ) - public List searchFinishedItems(@RequestParam( "term") String term, - @RequestParam( "is-segregated") boolean isSegregated ){ - return finishedItemDAO.findByTerm( term, isSegregated ); + @GetMapping("/search") + public List searchFinishedItems(@RequestParam("term") String term, + @RequestParam("is-segregated") boolean isSegregated) { + return finishedItemDAO.findByTerm(term, true); } - @GetMapping( "/search-packaging" ) - public List searchFinishedItemsForPackaging(@RequestParam( "term") String term, - @RequestParam( "is-segregated") boolean isSegregated ){ - return finishedItemDAO.findByTermForPackaging( term, true ); + + @GetMapping("/search-packaging") + public List searchFinishedItemsForPackaging(@RequestParam("term") String term, + @RequestParam("is-segregated") boolean isSegregated) { + return finishedItemDAO.findByTermForPackaging(term, true); } } diff --git a/src/main/java/com/utopiaindustries/service/InventoryService.java b/src/main/java/com/utopiaindustries/service/InventoryService.java index 7b6702d..a744bcb 100644 --- a/src/main/java/com/utopiaindustries/service/InventoryService.java +++ b/src/main/java/com/utopiaindustries/service/InventoryService.java @@ -44,55 +44,55 @@ public class InventoryService { this.packagingItemsDAO = packagingItemsDAO; } - private void updateJobCardInventoryStatus( JobCard card ){ - List items = jobCardItemDAO.findByCardId( card.getId( ) ); - for( JobCardItem item : items ){ + private void updateJobCardInventoryStatus(JobCard card) { + List items = jobCardItemDAO.findByCardId(card.getId()); + for (JobCardItem item : items) { // check if item is received - if( item.getActualProduction( ) == null || item.getActualProduction( ).compareTo( BigDecimal.ZERO ) == 0 ){ - return; + if (item.getActualProduction() == null || item.getActualProduction().compareTo(BigDecimal.ZERO) == 0) { + return; } } - card.setInventoryStatus( JobCard.InventoryStatus.RECEIVED.name( ) ); - jobCardDAO.save( card ); + card.setInventoryStatus(JobCard.InventoryStatus.RECEIVED.name()); + jobCardDAO.save(card); } /* * receive inv from job card * */ - @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) - public void receiveJobCardInventory( long jobCardId, JobCardWrapper jobCardWrapper ) { - if ( jobCardId == 0 || jobCardWrapper.getItems( ) == null || jobCardWrapper.getItems( ).isEmpty( ) ) { - throw new RuntimeException( " JobCard can`t be empty"); + @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED) + public void receiveJobCardInventory(long jobCardId, JobCardWrapper jobCardWrapper) { + if (jobCardId == 0 || jobCardWrapper.getItems() == null || jobCardWrapper.getItems().isEmpty()) { + throw new RuntimeException(" JobCard can`t be empty"); } - JobCard jobCard = jobCardDAO.find( jobCardId ); + JobCard jobCard = jobCardDAO.find(jobCardId); // get job cad items - List jobCardItemWrappers = jobCardWrapper.getItems( ); - List jobCardItemWrapperIds = jobCardItemWrappers.stream( ) - .map( JobCardItemWrapper::getJobCardItemId ) - .collect( Collectors.toList( ) ); + List jobCardItemWrappers = jobCardWrapper.getItems(); + List jobCardItemWrapperIds = jobCardItemWrappers.stream() + .map(JobCardItemWrapper::getJobCardItemId) + .collect(Collectors.toList()); - Map jobCardItemIdToActualProdMap = jobCardItemWrappers.stream( ) - .collect( Collectors.toMap( JobCardItemWrapper::getJobCardItemId, JobCardItemWrapper::getActualProduction ) ); + Map jobCardItemIdToActualProdMap = jobCardItemWrappers.stream() + .collect(Collectors.toMap(JobCardItemWrapper::getJobCardItemId, JobCardItemWrapper::getActualProduction)); - List items = jobCardItemDAO.findByIds( jobCardItemWrapperIds ); + List items = jobCardItemDAO.findByIds(jobCardItemWrapperIds); - if ( items != null && !items.isEmpty( ) ) { + if (items != null && !items.isEmpty()) { // get job card item ids - List jobCardItemIds = items.stream( ) - .map( JobCardItem::getId) - .collect( Collectors.toList( )); + List jobCardItemIds = items.stream() + .map(JobCardItem::getId) + .collect(Collectors.toList()); // save updated cut pieces - List cutPieces = jobCardItemWrappers.stream( ) - .flatMap( wrapper -> wrapper.getPieces( ).stream( ) ) - .collect( Collectors.toList( ) ); - cutPieceDAO.saveAll( cutPieces ); + List cutPieces = jobCardItemWrappers.stream() + .flatMap(wrapper -> wrapper.getPieces().stream()) + .collect(Collectors.toList()); + cutPieceDAO.saveAll(cutPieces); - Map> piecesMap = cutPieceDAO.findByJobCardItemIds( jobCardItemIds) - .stream( ) - .collect( Collectors.groupingBy( CutPiece::getJobCardItemId)); + Map> piecesMap = cutPieceDAO.findByJobCardItemIds(jobCardItemIds) + .stream() + .collect(Collectors.groupingBy(CutPiece::getJobCardItemId)); - for ( JobCardItem jobCardItem : items) { + for (JobCardItem jobCardItem : items) { int quantity = jobCardItemWrappers.stream() .filter(e -> e.getJobCardItemId() == jobCardItem.getId()) @@ -112,32 +112,32 @@ public class InventoryService { .findFirst() .orElse(BigDecimal.ZERO); - List bundles = createBundles( jobCardItem,quantity,jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , 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 ).add(jobCardItem.getActualProduction()) ); + createTransactions(bundles, jobCardItem.getAccountId(), InventoryArtifactType.BUNDLE.name()); + jobCardItem.setActualProduction(jobCardItemIdToActualProdMap.getOrDefault(jobCardItem.getId(), BigDecimal.ZERO).add(jobCardItem.getActualProduction())); jobCardItem.setComplete(cuttingComplete); } // update items with quantity - jobCardItemDAO.saveAll( items ); + jobCardItemDAO.saveAll(items); // update job card inv status - if(jobCardItemDAO.checkAllItemsComplete(jobCardId,jobCardItemIds)) { + if (jobCardItemDAO.checkAllItemsComplete(jobCardId, jobCardItemIds)) { updateJobCardInventoryStatus(jobCard); } } else { - throw new RuntimeException( "Items Not found in Job Card"); + throw new RuntimeException("Items Not found in Job Card"); } } /* * t create transactions * */ - private void createTransactions( List artifacts, long accountId, String parentDocumentType) { - if ( !artifacts.isEmpty( )) { - InventoryTransaction transaction = createInventoryTransaction( "Transaction Against " + parentDocumentType); - for ( InventoryArtifact artifact : artifacts) { - InventoryTransactionLeg leg = createInventoryTransactionLeg( transaction, artifact, accountId, InventoryTransactionLeg.Type.IN.name( ), parentDocumentType ); + private void createTransactions(List artifacts, long accountId, String parentDocumentType) { + if (!artifacts.isEmpty()) { + InventoryTransaction transaction = createInventoryTransaction("Transaction Against " + parentDocumentType); + for (InventoryArtifact artifact : artifacts) { + InventoryTransactionLeg leg = createInventoryTransactionLeg(transaction, artifact, accountId, InventoryTransactionLeg.Type.IN.name(), parentDocumentType); } } } @@ -146,93 +146,93 @@ public class InventoryService { /* * create and save transaction * */ - private InventoryTransaction createInventoryTransaction( String notes) { - Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); - InventoryTransaction transaction = new InventoryTransaction( ); - transaction.setGeneratedBy( authentication.getName( )); - transaction.setTransactionDateTime( LocalDateTime.now( )); - transaction.setNotes( notes); - transaction.setId( inventoryTransactionDAO.save( transaction)); + private InventoryTransaction createInventoryTransaction(String notes) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + InventoryTransaction transaction = new InventoryTransaction(); + transaction.setGeneratedBy(authentication.getName()); + transaction.setTransactionDateTime(LocalDateTime.now()); + transaction.setNotes(notes); + transaction.setId(inventoryTransactionDAO.save(transaction)); return transaction; } /* * create and save inventory transaction * */ - private InventoryTransactionLeg createInventoryTransactionLeg( InventoryTransaction transaction, + private InventoryTransactionLeg createInventoryTransactionLeg(InventoryTransaction transaction, InventoryArtifact artifact, long accountId, String transactionType, String parentDocumentType) { - InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg( ); - inventoryTransactionLeg.setTransactionId( transaction.getId( )); - inventoryTransactionLeg.setType( transactionType); - inventoryTransactionLeg.setQuantity( BigDecimal.valueOf( 1L)); - inventoryTransactionLeg.setAccountId( ( int) accountId); - inventoryTransactionLeg.setItemId( artifact.getItemId( )); - inventoryTransactionLeg.setSku( artifact.getSku( )); - inventoryTransactionLeg.setParentDocumentType( parentDocumentType); - inventoryTransactionLeg.setParentDocumentId( artifact.getId( )); - inventoryTransactionLeg.setParentDocumentPieceType( artifact.getType( )); - inventoryTransactionLeg.setTransactionLegDateTime( LocalDateTime.now( )); + InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg(); + inventoryTransactionLeg.setTransactionId(transaction.getId()); + inventoryTransactionLeg.setType(transactionType); + inventoryTransactionLeg.setQuantity(BigDecimal.valueOf(1L)); + inventoryTransactionLeg.setAccountId((int) accountId); + inventoryTransactionLeg.setItemId(artifact.getItemId()); + inventoryTransactionLeg.setSku(artifact.getSku()); + inventoryTransactionLeg.setParentDocumentType(parentDocumentType); + inventoryTransactionLeg.setParentDocumentId(artifact.getId()); + inventoryTransactionLeg.setParentDocumentPieceType(artifact.getType()); + inventoryTransactionLeg.setTransactionLegDateTime(LocalDateTime.now()); inventoryTransactionLeg.setJobCardId(artifact.getJobCardId()); // set balance - BigDecimal initialBalance = calculateBalance( accountId, artifact.getItemId( ), parentDocumentType, artifact.getType( )); + BigDecimal initialBalance = calculateBalance(accountId, artifact.getItemId(), parentDocumentType, artifact.getType()); - if ( transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.IN.name( ))) { - initialBalance = initialBalance.add( inventoryTransactionLeg.getQuantity( )); - }else if(transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.OUT.name( ))) { + if (transactionType.equalsIgnoreCase(InventoryTransactionLeg.Type.IN.name())) { + initialBalance = initialBalance.add(inventoryTransactionLeg.getQuantity()); + } else if (transactionType.equalsIgnoreCase(InventoryTransactionLeg.Type.OUT.name())) { if (inventoryTransactionLeg.getQuantity().equals(BigDecimal.ZERO)) { initialBalance = BigDecimal.ZERO; } else { initialBalance = initialBalance.subtract(inventoryTransactionLeg.getQuantity()); } } - inventoryTransactionLeg.setBalance( initialBalance); - inventoryTransactionLeg.setId( inventoryTransactionLegDAO.save( inventoryTransactionLeg)); + inventoryTransactionLeg.setBalance(initialBalance); + inventoryTransactionLeg.setId(inventoryTransactionLegDAO.save(inventoryTransactionLeg)); return inventoryTransactionLeg; } // calculate balance - private BigDecimal calculateBalance( long accountId, long itemId, String parentType, String pieceType) { + private BigDecimal calculateBalance(long accountId, long itemId, String parentType, String pieceType) { // find the last transaction leg of the current account Id with itemId - InventoryTransactionLeg lastTransactionLeg = inventoryTransactionLegDAO.findLastByAccountIdAndItemIdAndParentType( accountId, itemId, parentType, pieceType); - if ( lastTransactionLeg.getBalance( ) != null) { - return lastTransactionLeg.getBalance( ); + InventoryTransactionLeg lastTransactionLeg = inventoryTransactionLegDAO.findLastByAccountIdAndItemIdAndParentType(accountId, itemId, parentType, pieceType); + if (lastTransactionLeg.getBalance() != null) { + return lastTransactionLeg.getBalance(); } return BigDecimal.ZERO; } // create bundles from cut pieces - private List createBundles( JobCardItem jobCardItem, - int perBundleWrap, BigDecimal value ) { - Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); - if ( value != null && !value.equals(BigDecimal.ZERO)) { - List bundles = new ArrayList<>( ); - int quantity = value.intValue(); - int batchSize = perBundleWrap; - int iterations = (int) Math.ceil((double) quantity / batchSize); + private List createBundles(JobCardItem jobCardItem, + int perBundleWrap, BigDecimal value) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if (value != null && !value.equals(BigDecimal.ZERO)) { + List bundles = new ArrayList<>(); + int quantity = value.intValue(); + int batchSize = perBundleWrap; + 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 (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> entry : jobCardItemPieces ) { // JobCardItem key = entry.getKey( ); @@ -242,87 +242,87 @@ public class InventoryService { // } return bundles; } - return new ArrayList<>( ); + return new ArrayList<>(); } /* * receive inventory from master barcode * */ - @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) - public void receiveInventoryFromMasterBarcode( long masterId, long toAccount) { - if ( masterId == 0 || toAccount == 0) { - throw new RuntimeException( "Master Barcode | Account can`t be empty"); + @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED) + public void receiveInventoryFromMasterBarcode(long masterId, long toAccount) { + if (masterId == 0 || toAccount == 0) { + throw new RuntimeException("Master Barcode | Account can`t be empty"); } - MasterBundle masterBundle = masterBundleDAO.find( masterId); + MasterBundle masterBundle = masterBundleDAO.find(masterId); // find bundles from master barcode - List bundles = bundleDAO.findByMasterId( masterId); - if ( bundles != null && !bundles.isEmpty( )) { + List bundles = bundleDAO.findByMasterId(masterId); + if (bundles != null && !bundles.isEmpty()) { // bundle ids - List bundleIds = bundles.stream( ).map( Bundle::getId).collect( Collectors.toList( )); + List bundleIds = bundles.stream().map(Bundle::getId).collect(Collectors.toList()); Map lastBundleIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), bundleIds, InventoryArtifactType.BUNDLE.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), bundleIds, InventoryArtifactType.BUNDLE.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); // create Transaction - InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Cutting to Stitching"); - inventoryTransactionDAO.save( transaction); + InventoryTransaction transaction = createInventoryTransaction("Against Movement from Cutting to Stitching"); + inventoryTransactionDAO.save(transaction); // create transaction legs - for ( Bundle bundle : bundles) { - InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( bundle.getId( ), null); - if ( lastInvTransaction != null) { + for (Bundle bundle : bundles) { + InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(bundle.getId(), null); + if (lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId( ); - createInventoryTransactionLeg( transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.BUNDLE.name( )); + long fromAccount = lastInvTransaction.getAccountId(); + createInventoryTransactionLeg(transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.BUNDLE.name()); // IN bundle.setType("BUNDLE"); - createInventoryTransactionLeg( transaction, bundle, toAccount, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.STITCH_BUNDLE.name( )); + createInventoryTransactionLeg(transaction, bundle, toAccount, InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.STITCH_BUNDLE.name()); } } // update status - masterBundle.setIsReceived( true); + masterBundle.setIsReceived(true); masterBundle.setAccountId(toAccount); - masterBundleDAO.save( masterBundle); + masterBundleDAO.save(masterBundle); } } - private void validateItems( List cardItems) { - if ( cardItems == null || cardItems.isEmpty( )) { - throw new RuntimeException( "Item cant be Empty | null"); + private void validateItems(List cardItems) { + if (cardItems == null || cardItems.isEmpty()) { + throw new RuntimeException("Item cant be Empty | null"); } - for ( JobCardItem jobCardItem : cardItems) { - if( jobCardItem.getTotalProduction() != null ){ - int finalQuantity = jobCardItem.getActualProduction( ).compareTo( jobCardItem.getTotalProduction( ).add( jobCardItem.getProduction( ))); - if ( finalQuantity < 0) { - throw new RuntimeException( " Items cant be generated because it exceeds from limit of expected Production"); + for (JobCardItem jobCardItem : cardItems) { + if (jobCardItem.getTotalProduction() != null) { + int finalQuantity = jobCardItem.getActualProduction().compareTo(jobCardItem.getTotalProduction().add(jobCardItem.getProduction())); + if (finalQuantity < 0) { + throw new RuntimeException(" Items cant be generated because it exceeds from limit of expected Production"); } } } } - private void checkAllBundleAreReceived( long jobCardId, + private void checkAllBundleAreReceived(long jobCardId, List jobCardItems) { - if ( jobCardItems != null && !jobCardItems.isEmpty( ) ) { - List itemIds = jobCardItems.stream( ) - .filter( JobCardItem::getIsSelected ) - .map( JobCardItem::getItemId).collect( Collectors.toList( )); - List bundles = bundleDAO.findByItemIdsAndCardId( itemIds, jobCardId); - List masterBundleIds = bundles.stream( ).map( Bundle::getMasterBundleId).collect( Collectors.toList( )); - - Map idToMasterBundleMap = masterBundleDAO.findByIds( masterBundleIds) - .stream( ) - .collect( Collectors.toMap( MasterBundle::getId, Function.identity( ))); + if (jobCardItems != null && !jobCardItems.isEmpty()) { + List itemIds = jobCardItems.stream() + .filter(JobCardItem::getIsSelected) + .map(JobCardItem::getItemId).collect(Collectors.toList()); + List bundles = bundleDAO.findByItemIdsAndCardId(itemIds, jobCardId); + List masterBundleIds = bundles.stream().map(Bundle::getMasterBundleId).collect(Collectors.toList()); - for ( Bundle bundle : bundles) { + Map idToMasterBundleMap = masterBundleDAO.findByIds(masterBundleIds) + .stream() + .collect(Collectors.toMap(MasterBundle::getId, Function.identity())); + + for (Bundle bundle : bundles) { // check all bundles are received - MasterBundle masterBundle = idToMasterBundleMap.getOrDefault( bundle.getMasterBundleId( ), null); - if ( masterBundle == null || ! masterBundle.getIsReceived( ) ) { - throw new RuntimeException( "Please Receive Bundles Against Master Bundles First to Create Finished Item"); + MasterBundle masterBundle = idToMasterBundleMap.getOrDefault(bundle.getMasterBundleId(), null); + if (masterBundle == null || !masterBundle.getIsReceived()) { + throw new RuntimeException("Please Receive Bundles Against Master Bundles First to Create Finished Item"); } } } @@ -331,8 +331,8 @@ public class InventoryService { /* * create finished items from master bundles * */ - @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) - public void createStitchingOfflineItemsFromJobCard( BundleWrapper wrapper) { + @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED) + public void createStitchingOfflineItemsFromJobCard(BundleWrapper wrapper) { List updatedItems = new ArrayList<>(); List updateBundles = new ArrayList<>(); JobCard jobCard = null; @@ -349,17 +349,17 @@ public class InventoryService { .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); for (Bundle subBundle : wrapper.getBundles()) { long accountId = masterBundleDAO.find(subBundle.getMasterBundleId()).getAccountId(); - if(subBundle.getCurrentProduction() != null && subBundle.getCurrentProduction().compareTo(BigDecimal.ZERO) != 0){ + if (subBundle.getCurrentProduction() != null && subBundle.getCurrentProduction().compareTo(BigDecimal.ZERO) != 0) { Bundle bundle = bundleDAO.find(subBundle.getId()); jobCard = jobCardDAO.find(subBundle.getJobCardId()); - long production = (bundle.getProduction() == null) ? 0 : bundle.getProduction().longValue() ; + long production = (bundle.getProduction() == null) ? 0 : bundle.getProduction().longValue(); long wrapQuantity = bundle.getWrapQuantity().longValue(); - JobCardItem jobCardItem = jobCardItemDAO.findByCardIdAndItemId(subBundle.getJobCardId(),subBundle.getItemId()); + JobCardItem jobCardItem = jobCardItemDAO.findByCardIdAndItemId(subBundle.getJobCardId(), subBundle.getItemId()); BigDecimal previousTotalProduction = jobCardItem.getTotalProduction() == null ? BigDecimal.ZERO : jobCardItem.getTotalProduction(); InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(subBundle.getId(), null); - if (lastInvTransaction != null ) { + if (lastInvTransaction != null) { if (wrapQuantity == production + subBundle.getCurrentProduction().longValue()) { // OUT long fromAccount = lastInvTransaction.getAccountId(); @@ -367,7 +367,7 @@ public class InventoryService { } } // create stitchingOfflineItems items - List stitchingOfflineItems = createStitchingOfflineItems(subBundle.getCurrentProduction(),jobCardItem,subBundle.getId()); + List stitchingOfflineItems = createStitchingOfflineItems(subBundle.getCurrentProduction(), jobCardItem, subBundle.getId()); // create IN Transactions of Finished Items into account createTransactions(stitchingOfflineItems, accountId, InventoryArtifactType.STITCHING_OFFLINE.name()); @@ -385,24 +385,24 @@ public class InventoryService { /* * create finished items * */ - public List createStitchingOfflineItems( BigDecimal totalItem, JobCardItem jobCardItem,long bundleId) { - Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); - List items = new ArrayList<>( ); - if ( jobCardItem != null) { - for ( int i = 1; i <= totalItem.intValue( ); i++) { - StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem( ); - stitchingOfflineItem.setCreatedAt( LocalDateTime.now( )); - stitchingOfflineItem.setCreatedBy( authentication.getName( )); - stitchingOfflineItem.setItemId( jobCardItem.getItemId( )); - stitchingOfflineItem.setSku( jobCardItem.getSku( )); + public List createStitchingOfflineItems(BigDecimal totalItem, JobCardItem jobCardItem, long bundleId) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + List items = new ArrayList<>(); + if (jobCardItem != null) { + for (int i = 1; i <= totalItem.intValue(); i++) { + StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem(); + stitchingOfflineItem.setCreatedAt(LocalDateTime.now()); + stitchingOfflineItem.setCreatedBy(authentication.getName()); + stitchingOfflineItem.setItemId(jobCardItem.getItemId()); + stitchingOfflineItem.setSku(jobCardItem.getSku()); stitchingOfflineItem.setBundleId(bundleId); - stitchingOfflineItem.setJobCardId( jobCardItem.getJobCardId( )); - stitchingOfflineItem.setIsQa( false ); - long id = stitchingOfflineItemDAO.save( stitchingOfflineItem); - stitchingOfflineItem.setId( id); - stitchingOfflineItem.setBarcode( cryptographyService.generateRandomString( 15)); - stitchingOfflineItemDAO.save( stitchingOfflineItem); - items.add( stitchingOfflineItem); + stitchingOfflineItem.setJobCardId(jobCardItem.getJobCardId()); + stitchingOfflineItem.setIsQa(false); + long id = stitchingOfflineItemDAO.save(stitchingOfflineItem); + stitchingOfflineItem.setId(id); + stitchingOfflineItem.setBarcode(cryptographyService.generateRandomString(15)); + stitchingOfflineItemDAO.save(stitchingOfflineItem); + items.add(stitchingOfflineItem); } } return items; @@ -411,51 +411,51 @@ public class InventoryService { /* * find transactions by account id * */ - public List findTransactionByAccountId( long accountId) { - List legs = inventoryTransactionLegDAO.findByAccountId( accountId); + public List findTransactionByAccountId(long accountId) { + List legs = inventoryTransactionLegDAO.findByAccountId(accountId); - List tIds = legs.stream( ).map( InventoryTransactionLeg::getTransactionId).collect( Collectors.toList( )); - Map idToTransactioMap = inventoryTransactionDAO.findByIds( tIds).stream( ).collect( Collectors.toMap( InventoryTransaction::getId, Function.identity( ))); - legs.forEach( leg -> leg.setTransaction( idToTransactioMap.get( leg.getTransactionId( )))); + List tIds = legs.stream().map(InventoryTransactionLeg::getTransactionId).collect(Collectors.toList()); + Map idToTransactioMap = inventoryTransactionDAO.findByIds(tIds).stream().collect(Collectors.toMap(InventoryTransaction::getId, Function.identity())); + legs.forEach(leg -> leg.setTransaction(idToTransactioMap.get(leg.getTransactionId()))); return legs; } /* * * */ - @Transactional( rollbackFor = Exception.class) - public void markFinishedItemsApproved( List fItemIds, long toAccount) { + @Transactional(rollbackFor = Exception.class) + public void markFinishedItemsApproved(List fItemIds, long toAccount) { - if ( fItemIds.isEmpty( ) || toAccount == 0) { - throw new RuntimeException( "Finished Item Ids | Account can`t be empty"); + if (fItemIds.isEmpty() || toAccount == 0) { + throw new RuntimeException("Finished Item Ids | Account can`t be empty"); } - List finishedItems = finishedItemDAO.findByIds( fItemIds); - if ( finishedItems != null && !finishedItems.isEmpty( )) { + List finishedItems = finishedItemDAO.findByIds(fItemIds); + if (finishedItems != null && !finishedItems.isEmpty()) { // bundle ids - List finishedItemIds = finishedItems.stream( ).map( FinishedItem::getId).collect( Collectors.toList( )); + List finishedItemIds = finishedItems.stream().map(FinishedItem::getId).collect(Collectors.toList()); Map lastBundleIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); // create Transaction - InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Stitching to Packaging After QA"); - inventoryTransactionDAO.save( transaction); + InventoryTransaction transaction = createInventoryTransaction("Against Movement from Stitching to Packaging After QA"); + inventoryTransactionDAO.save(transaction); // create transaction legs - for ( FinishedItem finishedItem : finishedItems) { - InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); - if ( lastInvTransaction != null) { + for (FinishedItem finishedItem : finishedItems) { + InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(finishedItem.getId(), null); + if (lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId( ); - createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); + long fromAccount = lastInvTransaction.getAccountId(); + createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCHING_OFFLINE.name()); // IN - createInventoryTransactionLeg( transaction, finishedItem, toAccount, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); + createInventoryTransactionLeg(transaction, finishedItem, toAccount, InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.STITCHING_OFFLINE.name()); } - finishedItem.setIsQa( true); + finishedItem.setIsQa(true); } - finishedItemDAO.saveAll( finishedItems); + finishedItemDAO.saveAll(finishedItems); } } @@ -463,81 +463,94 @@ public class InventoryService { /* * generate finished items against stitched items * */ - @Transactional( rollbackFor = Exception.class) - public void createFinishedItemsAgainstStitchedItems( StitchedItemWrapper wrapper ) { - if ( wrapper.getItems( ) != null && wrapper.getFinishedAccountId( ) != 0) { - Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); + @Transactional(rollbackFor = Exception.class) + public void createFinishedItemsAgainstStitchedItems(StitchedItemWrapper wrapper, String qaStatus) { + if (wrapper.getItems() != null && wrapper.getFinishedAccountId() != 0) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - List stitchingOfflineItems = wrapper.getItems( ); - List updatedStitchedItems = new ArrayList<>( ); - List finishedItems = new ArrayList<>( ); + List stitchingOfflineItems = wrapper.getItems(); + List updatedStitchedItems = new ArrayList<>(); + List finishedItems = new ArrayList<>(); + List finishedItemsForUlter = new ArrayList<>(); - List stitchedItemIds = stitchingOfflineItems.stream( ) - .map( StitchingOfflineItem::getId) - .collect( Collectors.toList( )); + List stitchedItemIds = stitchingOfflineItems.stream() + .map(StitchingOfflineItem::getId) + .collect(Collectors.toList()); Map lastStitchedIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); // get finished items from stitched items if exists - List preCreatedFinishedItemIds = finishedItemDAO.findByStitchedItemIds( stitchedItemIds ).stream( ). - map( FinishedItem::getId ).collect( Collectors.toList( )); + List preCreatedFinishedItemIds = finishedItemDAO.findByStitchedItemIds(stitchedItemIds).stream(). + map(FinishedItem::getId).collect(Collectors.toList()); Map lastFinishedItemInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), preCreatedFinishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), preCreatedFinishedItemIds, InventoryArtifactType.FINISHED_ITEM.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); - InventoryTransaction transaction = createInventoryTransaction( "Against Movement From Stitching Offline to Finished Item"); + InventoryTransaction transaction = createInventoryTransaction("Against Movement From Stitching Offline to Finished Item"); // generate FI for SI - for ( StitchingOfflineItem stitchingOfflineItem : stitchingOfflineItems) { - if ( stitchingOfflineItem.getQaStatus( ).equalsIgnoreCase( "APPROVED" )) { + for (StitchingOfflineItem stitchingOfflineItem : stitchingOfflineItems) { + if (qaStatus.equalsIgnoreCase("APPROVED")) { // check finished item is already created - FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem( stitchingOfflineItem.getId( )); - if ( preCreatedItem == null) { - FinishedItem finishedItem = new FinishedItem( ); - finishedItem.setItemId( stitchingOfflineItem.getItemId( )); - finishedItem.setSku( stitchingOfflineItem.getSku( )); - finishedItem.setBarcode( stitchingOfflineItem.getBarcode( )); - finishedItem.setCreatedBy( authentication.getName( )); - finishedItem.setCreatedAt( LocalDateTime.now( )); - finishedItem.setStitchedItemId( stitchingOfflineItem.getId( )); - finishedItem.setJobCardId( stitchingOfflineItem.getJobCardId( )); - finishedItem.setIsQa( false); - finishedItem.setId( finishedItemDAO.save( finishedItem)); - finishedItems.add( finishedItem); - InventoryTransactionLeg lastInvTransaction = lastStitchedIdInTransactionMap.getOrDefault( stitchingOfflineItem.getId( ), null); - if ( lastInvTransaction != null ) { + FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem(stitchingOfflineItem.getId()); + if (preCreatedItem == null) { + FinishedItem finishedItem = new FinishedItem(); + finishedItem.setItemId(stitchingOfflineItem.getItemId()); + finishedItem.setSku(stitchingOfflineItem.getSku()); + finishedItem.setBarcode(stitchingOfflineItem.getBarcode()); + finishedItem.setCreatedBy(authentication.getName()); + finishedItem.setCreatedAt(LocalDateTime.now()); + finishedItem.setStitchedItemId(stitchingOfflineItem.getId()); + finishedItem.setJobCardId(stitchingOfflineItem.getJobCardId()); + finishedItem.setIsQa(true); + finishedItem.setId(finishedItemDAO.save(finishedItem)); + finishedItems.add(finishedItem); + InventoryTransactionLeg lastInvTransaction = lastStitchedIdInTransactionMap.getOrDefault(stitchingOfflineItem.getId(), null); + if (lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId( ); - createInventoryTransactionLeg( transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); + long fromAccount = lastInvTransaction.getAccountId(); + createInventoryTransactionLeg(transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCHING_OFFLINE.name()); } // update stitched item - stitchingOfflineItem.setIsQa( true); + stitchingOfflineItem.setIsQa(true); + stitchingOfflineItem.setQaStatus(qaStatus); + updatedStitchedItems.add(stitchingOfflineItem); // if FI is already created } else { // create OUT from stitching account Finished Item - InventoryTransactionLeg lastInvTransaction = lastFinishedItemInTransactionMap.getOrDefault( preCreatedItem.getId( ), null); - if ( lastInvTransaction != null ) { + InventoryTransactionLeg lastInvTransaction = lastFinishedItemInTransactionMap.getOrDefault(preCreatedItem.getId(), null); + if (lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId( ); - createInventoryTransactionLeg( transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); + long fromAccount = lastInvTransaction.getAccountId(); + createInventoryTransactionLeg(transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name()); } + preCreatedItem.setIsQa(true); + finishedItemsForUlter.add(preCreatedItem); // create IN in finishing Account Finished Item - finishedItems.add( preCreatedItem ); + finishedItems.add(preCreatedItem); } + } else { + FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem(stitchingOfflineItem.getId()); + preCreatedItem.setIsQa(false); + finishedItemsForUlter.add(preCreatedItem); } + stitchingOfflineItem.setIsQa(true); + stitchingOfflineItem.setQaStatus(qaStatus); + updatedStitchedItems.add(stitchingOfflineItem); } - for ( FinishedItem finishedItem : finishedItems) { + for (FinishedItem finishedItem : finishedItems) { // IN - createInventoryTransactionLeg( transaction, finishedItem, wrapper.getFinishedAccountId( ), InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); + createInventoryTransactionLeg(transaction, finishedItem, wrapper.getFinishedAccountId(), InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.FINISHED_ITEM.name()); } // save updated stitched items - stitchingOfflineItemDAO.saveAll( wrapper.getItems( )); + finishedItemDAO.saveAll(finishedItemsForUlter); + stitchingOfflineItemDAO.saveAll(updatedStitchedItems); } } @@ -545,139 +558,163 @@ public class InventoryService { /* * segregate finish items * */ - @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) - public void segregateFinishedItems( FinishedItemWrapper wrapper) { - if ( wrapper != null && wrapper.getItems( ) != null) { + @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED) + public void segregateFinishedItems(FinishedItemWrapper wrapper, String status) { + if (wrapper != null && wrapper.getItems() != null) { - List items = wrapper.getItems( ); - List updatedItems = new ArrayList<>( ); + List items = wrapper.getItems(); + List updatedItems = new ArrayList<>(); // finished ids - List finishedItemIds = items.stream( ).map( FinishedItem::getId) - .collect( Collectors.toList( )); + List finishedItemIds = items.stream().map(FinishedItem::getId) + .collect(Collectors.toList()); // stitched ids - List stitchedItemIds = items.stream( ).map( FinishedItem::getStitchedItemId) - .collect( Collectors.toList( )); + List stitchedItemIds = items.stream().map(FinishedItem::getStitchedItemId) + .collect(Collectors.toList()); // create parent doc type last IN transaction map Map lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); // create parent doc type last OUT transaction map Map lastStitchedItemOutTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.OUT.name( ), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.OUT.name(), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); // create transaction - InventoryTransaction transaction = createInventoryTransaction( "Against Segregation of Finished Items"); - + InventoryTransaction transaction = createInventoryTransaction("Against Segregation of Finished Items"); // create IN and OUT for all approved items - for ( FinishedItem finishedItem : items) { - InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); - finishedItem.setIsQa( true); - /* - * item is not approved and washed is selected then item remain in Finishing account - * */ + for (FinishedItem finishedItem : items) { + InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault(finishedItem.getId(), null); + finishedItem.setIsQa(true); /* * item is approved and alter is selected then finished item will to stitching account * */ - if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "ALTER")) { + if (status.equalsIgnoreCase("ALTER")) { // create OUT and IN transactions for FI - if ( lastInvTransaction != null) { + if (lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId( ); - createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); + long fromAccount = lastInvTransaction.getAccountId(); + createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name()); // IN // get the stitching account id - long stitchedItemId = finishedItem.getStitchedItemId( ); - InventoryTransactionLeg lastOutTransaction = lastStitchedItemOutTransactionMap.getOrDefault( stitchedItemId, null); - createInventoryTransactionLeg( transaction, finishedItem, lastOutTransaction.getAccountId( ), InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); + long stitchedItemId = finishedItem.getStitchedItemId(); + InventoryTransactionLeg lastOutTransaction = lastStitchedItemOutTransactionMap.getOrDefault(stitchedItemId, null); + createInventoryTransactionLeg(transaction, finishedItem, lastOutTransaction.getAccountId(), InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.FINISHED_ITEM.name()); + finishedItem.setQaStatus("ALTER"); + finishedItem.setIsSegregated(false); } } + /* + * item is not approved and washed is selected then item remain in Finishing account + * */ + if (status.equalsIgnoreCase("WASHED")) { + finishedItem.setIsSegregated(false); + finishedItem.setQaStatus("WASHED"); + } + + /* + * item is not approved and B grade is selected then item remain in Finishing account because after + * alteration item will be moved to A grade account for segregation + * */ + if (status.equalsIgnoreCase("B GRADE")) { + finishedItem.setIsSegregated(false); + finishedItem.setQaStatus("B GRADE"); + } + + /* + * item is not approved and C grade is selected then item remain in Finishing account because after + * alteration item will be moved to A grade account for segregation + * */ + if (status.equalsIgnoreCase("C GRADE")) { + finishedItem.setIsSegregated(false); + finishedItem.setQaStatus("C GRADE"); + } + /* * item is approved and grade is selected then fI is move to grade account */ - if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "APPROVED") && finishedItem.getAccountId( ) != 0) { - finishedItem.setIsSegregated( true); + if (status.equalsIgnoreCase("APPROVED")) { + finishedItem.setQaStatus("APPROVED"); + finishedItem.setIsSegregated(true); } - updatedItems.add( finishedItem); + updatedItems.add(finishedItem); } // save finish items - finishedItemDAO.saveAll( updatedItems); + finishedItemDAO.saveAll(updatedItems); } } /* * Packaging items * */ - @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) - public void createPackagingItemAndTransaction( FinishedItemWrapper wrapper) { - if ( wrapper != null && wrapper.getItems( ) != null) { + @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED) + public void createPackagingItemAndTransaction(FinishedItemWrapper wrapper) { + if (wrapper != null && wrapper.getItems() != null) { - List items = wrapper.getItems( ); - List updatedItems = new ArrayList<>( ); - List packagingItems = new ArrayList<>( ); + List items = wrapper.getItems(); + List updatedItems = new ArrayList<>(); + List packagingItems = new ArrayList<>(); // finished ids - List finishedItemIds = items.stream( ).map( FinishedItem::getId) - .collect( Collectors.toList( )); + List finishedItemIds = items.stream().map(FinishedItem::getId) + .collect(Collectors.toList()); // stitched ids - List stitchedItemIds = items.stream( ).map( FinishedItem::getStitchedItemId) - .collect( Collectors.toList( )); + List stitchedItemIds = items.stream().map(FinishedItem::getStitchedItemId) + .collect(Collectors.toList()); // find parent doc type last IN transaction map Map lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) - .stream( ) - .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); + .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name()) + .stream() + .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); // create transaction - InventoryTransaction transaction = createInventoryTransaction( "Against Segregation of Finished Items"); + InventoryTransaction transaction = createInventoryTransaction("Against Segregation of Finished Items"); // create IN and OUT for all approved items - for ( FinishedItem finishedItem : items) { - InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); - finishedItem.setIsQa( true); + for (FinishedItem finishedItem : items) { + InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault(finishedItem.getId(), null); + finishedItem.setIsQa(true); - if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "APPROVED") && finishedItem.getIsSegregated( )) { + if (finishedItem.getQaStatus().equalsIgnoreCase("APPROVED") && finishedItem.getIsSegregated()) { // create OUT and IN transactions for FI PackagingItems packagingItems1 = (createPackagingItem(finishedItem)); packagingItems1.setId(packagingItemsDAO.save(packagingItems1)); - if ( lastInvTransaction != null) { + if (lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId( ); - createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); + long fromAccount = lastInvTransaction.getAccountId(); + createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name()); // IN - createInventoryTransactionLeg( transaction, packagingItems1, 8, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.PACKAGING.name( )); + createInventoryTransactionLeg(transaction, packagingItems1, 8, InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.PACKAGING.name()); } - finishedItem.setIsSegregated( true); - finishedItem.setPackaging( true); + finishedItem.setIsSegregated(true); + finishedItem.setPackaging(true); packagingItems.add(packagingItems1); } - updatedItems.add( finishedItem); + updatedItems.add(finishedItem); } // save finish items - finishedItemDAO.saveAll( updatedItems); + finishedItemDAO.saveAll(updatedItems); packagingItemsDAO.saveAll(packagingItems); } } - /* * find item summary by account * */ - public List findItemSummaryByAccountId( long accountId) { - return inventoryTransactionLegDAO.findSummaryByAccountId( accountId); + public List findItemSummaryByAccountId(long accountId) { + return inventoryTransactionLegDAO.findSummaryByAccountId(accountId); } - private PackagingItems createPackagingItem(FinishedItem finishedItem){ - Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); + private PackagingItems createPackagingItem(FinishedItem finishedItem) { + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); PackagingItems packagingItems = new PackagingItems(); packagingItems.setItemId(finishedItem.getItemId()); packagingItems.setAccountId(finishedItem.getAccountId()); @@ -687,7 +724,7 @@ public class InventoryService { packagingItems.setSku(finishedItem.getSku()); packagingItems.setBarcode(finishedItem.getBarcode()); packagingItems.setCreatedAt(LocalDateTime.now()); - packagingItems.setCreatedBy(authentication.getName( )); + packagingItems.setCreatedBy(authentication.getName()); packagingItems.setIsQa(finishedItem.getIsQa()); packagingItems.setIsSegregated(finishedItem.getIsSegregated()); packagingItems.setQaStatus(finishedItem.getQaStatus()); 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..4c55659 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 @@ -1,9 +1,8 @@ -( async function(){ - +(async function () { Vue.prototype.$accounts = window.ctp.accounts; - Vue.component('finished-item-table',{ - props : [ 'items' ], + Vue.component('finished-item-table', { + props: ['items'], methods: { getFormattedDateTime: function (dateTime) { if (!!dateTime) { @@ -15,8 +14,8 @@ this.$emit('remove-item', index) } }, - template : ` - + template: ` +
@@ -27,68 +26,53 @@ - - - + + + NOT PERFORMED + {{ item.qaStatus }} + {{ item.qaStatus }} + {{ item.qaStatus }} - -
IDJob Card ID Barcode StatusAccount Action
- - - - - - - - - - - {{item.id}} + + + + + + + + + + + {{item.id}} {{item.itemId}} {{item.sku}} {{item.createdBy}} {{ getFormattedDateTime( item.createdAt) }} {{item.jobCardId}} {{ getFormattedDateTime(item.createdAt) }} {{item.jobCardId}} {{item.barcode}} -
- - - -
- - -
- `, - - }) + + ` + }); let app = new Vue({ - el : '#finishedApp', - data : { - items : [] + el: '#finishedApp', + data: { + items: [], + QaStatus: 'APPROVED' }, - methods : { + methods: { onItemSelect: function (id, item) { this.items.push(item); }, @@ -100,10 +84,15 @@ const uniqueIds = new Set(ids); return ids.length !== uniqueIds.size; }, + submitWithQaStatus: function (status) { + this.QaStatus = status; + this.$nextTick(() => { + document.getElementById('finishedApp').submit(); + }); + } }, - mounted : function () { - console.log( this.$accounts ) + mounted: function () { + console.log(this.$accounts); } - }) - -})(jQuery) \ No newline at end of file + }); +})(jQuery); diff --git a/src/main/resources/static/js/packaging/packaging-item-form.js b/src/main/resources/static/js/packaging/packaging-item-form.js index ad0c744..55adca8 100644 --- a/src/main/resources/static/js/packaging/packaging-item-form.js +++ b/src/main/resources/static/js/packaging/packaging-item-form.js @@ -53,7 +53,13 @@ {{ getFormattedDateTime( item.createdAt) }} {{item.jobCardId}} {{item.barcode}} - {{item.qaStatus}} + + NOT PERFORMED + {{ item.qaStatus }} + {{ item.qaStatus }} + {{ item.qaStatus }} + + - Cancel - - - - + - +
+
Finished Items
+ +
+
Duplicate Item Selected
+ + + + + + Cancel + + + + -
- + + +
+ \ No newline at end of file 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 006bd8d..f7e2877 100644 --- a/src/main/resources/templates/quality-control/qc-items-form.html +++ b/src/main/resources/templates/quality-control/qc-items-form.html @@ -1,55 +1,61 @@ - - -
- -
-
-
-

Add Stitched Offline Items For QC

+ + +
+ +
+
+
+

Add Stitched Offline Items For QC

+
+
+
+
+
+ + +
+ +
+ + +
- -
-
-
- - -
-
- - -
-
-
-
-
Stitched Items
- - -
-
Duplicate Item Selected
- - Cancel - - - -
-
+
+
Stitched Items
+ + +
+
Duplicate Item Selected
+ + + Cancel + + + +
-
- +
+
+
+ \ No newline at end of file