Compare commits

...

5 Commits

14 changed files with 785 additions and 723 deletions

View File

@ -9,6 +9,6 @@ import java.lang.annotation.Target;
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE}) @Target({ElementType.METHOD, ElementType.TYPE})
@PreAuthorize( "hasAnyRole('ROLE_ADMIN')") @PreAuthorize("hasAnyRole('ROLE_ADMIN')")
public @interface AdminRole { public @interface AdminRole {
} }

View File

@ -19,7 +19,7 @@ import java.util.List;
@Controller @Controller
@FinishingRole @FinishingRole
@RequestMapping( "/finishing" ) @RequestMapping("/finishing")
public class FinishingController { public class FinishingController {
private final FinishedItemDAO finishedItemDAO; private final FinishedItemDAO finishedItemDAO;
@ -37,26 +37,26 @@ public class FinishingController {
} }
@GetMapping @GetMapping
public String showHome(Model model ){ public String showHome(Model model) {
return "redirect:/finishing/finished-items"; return "redirect:/finishing/finished-items";
} }
@GetMapping( "/finished-items" ) @GetMapping("/finished-items")
public String showFinishedItems( @RequestParam(value = "id", required = false ) String id, public String showFinishedItems(@RequestParam(value = "id", required = false) String id,
@RequestParam(value = "item-id", required = false ) String itemId, @RequestParam(value = "item-id", required = false) String itemId,
@RequestParam( value = "sku", required = false ) String sku, @RequestParam(value = "sku", required = false) String sku,
@RequestParam( value = "start-date", required = false) String startDate, @RequestParam(value = "start-date", required = false) String startDate,
@RequestParam( value = "end-date", required = false ) String endDate, @RequestParam(value = "end-date", required = false) String endDate,
@RequestParam( value = "job-card-id", required = false ) String jobCardId, @RequestParam(value = "job-card-id", required = false) String jobCardId,
@RequestParam( value = "count", required = false ) Long count, @RequestParam(value = "count", required = false) Long count,
Model model ){ Model model) {
LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(30) : LocalDate.parse(startDate); LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(30) : LocalDate.parse(startDate);
LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate);
model.addAttribute("startDate", startDate1); model.addAttribute("startDate", startDate1);
model.addAttribute("endDate", endDate1); model.addAttribute("endDate", endDate1);
List<FinishedItem> itemList = bundleService.getFinishedItem( id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId ,count ); List<FinishedItem> itemList = bundleService.getFinishedItem(id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId, count);
model.addAttribute("items", itemList ) ; model.addAttribute("items", itemList);
return "finishing/finished-item-list"; return "finishing/finished-item-list";
} }
@ -65,39 +65,38 @@ public class FinishingController {
/* /*
* get finishing inventory accounts * get finishing inventory accounts
* */ * */
@GetMapping( "/inventory-accounts" ) @GetMapping("/inventory-accounts")
public String getInventoryAccounts( @RequestParam( value = "id", required = false ) String id, public String getInventoryAccounts(@RequestParam(value = "id", required = false) String id,
@RequestParam( value = "title", required = false) String title, @RequestParam(value = "title", required = false) String title,
@RequestParam( value = "active", required = false ) String active, @RequestParam(value = "active", required = false) String active,
@RequestParam( value = "created-by", required = false ) String createdBy, @RequestParam(value = "created-by", required = false) String createdBy,
@RequestParam( value = "start-date", required = false ) String startDate, @RequestParam(value = "start-date", required = false) String startDate,
@RequestParam( value = "end-date", required = false ) String endDate, @RequestParam(value = "end-date", required = false) String endDate,
@RequestParam( value = "site-id", required = false ) String siteId, @RequestParam(value = "site-id", required = false) String siteId,
@RequestParam( value = "count", required = false, defaultValue = "100") Long count, @RequestParam(value = "count", required = false, defaultValue = "100") Long count,
Model model ) { Model model) {
// 5 for Finishing // 5 for Finishing
model.addAttribute("accounts", inventoryAccountService.getInventoryAccounts( id, title, active, createdBy, startDate, endDate, siteId, count, "PROCESS", "5" , false )); model.addAttribute("accounts", inventoryAccountService.getInventoryAccounts(id, title, active, createdBy, startDate, endDate, siteId, count, "PROCESS", "5", false));
model.addAttribute("locations", locationService.findAll() ); model.addAttribute("locations", locationService.findAll());
return "/finishing/inventory-accounts"; return "/finishing/inventory-accounts";
} }
@GetMapping( "segregate-inventory" ) @GetMapping("segregate-inventory")
public String segregateFinishedItems( Model model ){ public String segregateFinishedItems(Model model) {
model.addAttribute("accounts", inventoryAccountService.findInventoryAccountsForFinishedItems() ); model.addAttribute("wrapper", new FinishedItemWrapper());
model.addAttribute("wrapper", new FinishedItemWrapper() );
return "/finishing/segregate-inventory"; return "/finishing/segregate-inventory";
} }
@PostMapping( "segregate-inventory" ) @PostMapping("segregate-inventory")
public String segregateFinishItemsInventory( @ModelAttribute FinishedItemWrapper wrapper, public String segregateFinishItemsInventory(@ModelAttribute FinishedItemWrapper wrapper,
RedirectAttributes redirectAttributes, RedirectAttributes redirectAttributes,
Model model ){ Model model) {
try { try {
inventoryService.segregateFinishedItems( wrapper ); inventoryService.segregateFinishedItems(wrapper, wrapper.getQaStatus());
redirectAttributes.addFlashAttribute("success", "Items Successfully saved !" ); redirectAttributes.addFlashAttribute("success", "Items Successfully saved !");
} catch ( Exception e ){ } catch (Exception e) {
redirectAttributes.addFlashAttribute("error", e.getMessage() ); redirectAttributes.addFlashAttribute("error", e.getMessage());
} }
return "redirect:/finishing/segregate-inventory"; return "redirect:/finishing/segregate-inventory";
} }

View File

@ -18,7 +18,7 @@ import java.util.List;
@Controller @Controller
@QCRole @QCRole
@RequestMapping( "/quality-control" ) @RequestMapping("/quality-control")
public class QualityControlController { public class QualityControlController {
private final InventoryAccountService inventoryAccountService; private final InventoryAccountService inventoryAccountService;
@ -34,63 +34,63 @@ public class QualityControlController {
} }
@GetMapping @GetMapping
public String homePage( Model model ){ public String homePage(Model model) {
return "redirect:/quality-control/qc-finished-items"; return "redirect:/quality-control/qc-finished-items";
} }
/* /*
* get stitching inventory accounts * get stitching inventory accounts
* */ * */
@GetMapping( "/inventory-accounts" ) @GetMapping("/inventory-accounts")
public String getInventoryAccounts( @RequestParam( value = "id", required = false ) String id, public String getInventoryAccounts(@RequestParam(value = "id", required = false) String id,
@RequestParam( value = "title", required = false) String title, @RequestParam(value = "title", required = false) String title,
@RequestParam( value = "active", required = false ) String active, @RequestParam(value = "active", required = false) String active,
@RequestParam( value = "created-by", required = false ) String createdBy, @RequestParam(value = "created-by", required = false) String createdBy,
@RequestParam( value = "start-date", required = false ) String startDate, @RequestParam(value = "start-date", required = false) String startDate,
@RequestParam( value = "end-date", required = false ) String endDate, @RequestParam(value = "end-date", required = false) String endDate,
@RequestParam( value = "site-id", required = false ) String siteId, @RequestParam(value = "site-id", required = false) String siteId,
@RequestParam( value = "count", required = false ) Long count, @RequestParam(value = "count", required = false) Long count,
Model model ) { Model model) {
// 24 for Packaging // 24 for Packaging
model.addAttribute("accounts", inventoryAccountService.getInventoryAccounts(id, title, active, createdBy, startDate, endDate, siteId, count, "PROCESS", "4", false)); 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"; return "/quality-control/inventory-accounts";
} }
@GetMapping( "/qc-finished-items" ) @GetMapping("/qc-finished-items")
public String getFinishedItems( @RequestParam(value = "id", required = false ) String id, public String getFinishedItems(@RequestParam(value = "id", required = false) String id,
@RequestParam(value = "item-id", required = false ) String itemId, @RequestParam(value = "item-id", required = false) String itemId,
@RequestParam( value = "sku", required = false ) String sku, @RequestParam(value = "sku", required = false) String sku,
@RequestParam( value = "start-date", required = false) String startDate, @RequestParam(value = "start-date", required = false) String startDate,
@RequestParam( value = "end-date", required = false ) String endDate, @RequestParam(value = "end-date", required = false) String endDate,
@RequestParam( value = "job-card-id", required = false ) String jobCardId, @RequestParam(value = "job-card-id", required = false) String jobCardId,
@RequestParam( value = "count", required = false, defaultValue = "100") Long count, @RequestParam(value = "count", required = false, defaultValue = "100") Long count,
Model model ){ Model model) {
LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(30) : LocalDate.parse(startDate); LocalDate startDate1 = StringUtils.isNullOrEmpty(startDate) ? LocalDate.now().minusDays(30) : LocalDate.parse(startDate);
LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate); LocalDate endDate1 = StringUtils.isNullOrEmpty(endDate) ? LocalDate.now() : LocalDate.parse(endDate);
model.addAttribute("startDate", startDate1); model.addAttribute("startDate", startDate1);
model.addAttribute("endDate", endDate1); model.addAttribute("endDate", endDate1);
List<FinishedItem> itemList = bundleService.getFinishedItem( id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId ,count ); List<FinishedItem> itemList = bundleService.getFinishedItem(id, itemId, sku, startDate1.toString(), endDate1.toString(), jobCardId, count);
model.addAttribute("items", itemList ) ; model.addAttribute("items", itemList);
return "/quality-control/qc-items-list"; return "/quality-control/qc-items-list";
} }
@GetMapping( "/qc-finished-item" ) @GetMapping("/qc-finished-item")
public String getAddFinishedItemForQCForm( Model model ){ public String getAddFinishedItemForQCForm(Model model) {
// 4 for packaging // 4 for packaging
model.addAttribute("accounts", inventoryAccountService.findInventoryAccounts(5L) ); model.addAttribute("accounts", inventoryAccountService.findInventoryAccounts(5L));
model.addAttribute("wrapper", new StitchedItemWrapper() ); model.addAttribute("wrapper", new StitchedItemWrapper());
return "/quality-control/qc-items-form"; return "/quality-control/qc-items-form";
} }
@PostMapping( "/qc-finished-item" ) @PostMapping("/qc-finished-item")
public String postFinishedItemsAfterQc( @ModelAttribute StitchedItemWrapper wrapper, public String postFinishedItemsAfterQc(@ModelAttribute StitchedItemWrapper wrapper,
RedirectAttributes redirectAttributes ){ RedirectAttributes redirectAttributes) {
try { try {
inventoryService.createFinishedItemsAgainstStitchedItems( wrapper ); inventoryService.createFinishedItemsAgainstStitchedItems(wrapper, wrapper.getQaStatus());
redirectAttributes.addFlashAttribute("success", " Finished Items Are Generated Against Stitched Items" ); redirectAttributes.addFlashAttribute("success", " Finished Items Are Generated Against Stitched Items");
}catch ( Exception ex ){ } catch (Exception ex) {
redirectAttributes.addFlashAttribute("error", ex.getMessage() ); redirectAttributes.addFlashAttribute("error", ex.getMessage());
} }
return "redirect:/quality-control/qc-finished-item"; return "redirect:/quality-control/qc-finished-item";
} }

View File

@ -17,182 +17,182 @@ import java.util.List;
@Repository @Repository
public class FinishedItemDAO { public class FinishedItemDAO {
private final NamedParameterJdbcTemplate namedParameterJdbcTemplate; private final NamedParameterJdbcTemplate namedParameterJdbcTemplate;
private final String TABLE_NAME = "cut_to_pack.finished_item"; 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_QUERY = String.format("SELECT * FROM %s WHERE id = :id", TABLE_NAME);
private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id DESC", TABLE_NAME ); private final String SELECT_ALL_QUERY = String.format("SELECT * FROM %s ORDER BY id DESC", TABLE_NAME);
private final String 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_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 SELECT_QUERY_BY_JOB_CARD = String.format("SELECT * FROM %s WHERE job_card_id = :job_card_id", TABLE_NAME);
private final String DELETE_QUERY = String.format( "DELETE FROM %s WHERE id = :id", TABLE_NAME ); private final String DELETE_QUERY = String.format("DELETE FROM %s WHERE id = :id", TABLE_NAME);
private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, item_id, sku, barcode, created_at, created_by, job_card_id, is_qa, 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 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_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 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 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 = 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_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_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 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 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 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) { public FinishedItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) {
this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; this.namedParameterJdbcTemplate = namedParameterJdbcTemplate;
} }
// prepare query params // prepare query params
private MapSqlParameterSource prepareInsertQueryParams( FinishedItem finishedItem ) { private MapSqlParameterSource prepareInsertQueryParams(FinishedItem finishedItem) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", finishedItem.getId() ) params.addValue("id", finishedItem.getId())
.addValue( "item_id", finishedItem.getItemId() ) .addValue("item_id", finishedItem.getItemId())
.addValue( "sku", finishedItem.getSku() ) .addValue("sku", finishedItem.getSku())
.addValue( "barcode", finishedItem.getBarcode() ) .addValue("barcode", finishedItem.getBarcode())
.addValue( "created_at", finishedItem.getCreatedAt() ) .addValue("created_at", finishedItem.getCreatedAt())
.addValue( "created_by", finishedItem.getCreatedBy() ) .addValue("created_by", finishedItem.getCreatedBy())
.addValue("job_card_id", finishedItem.getJobCardId() ) .addValue("job_card_id", finishedItem.getJobCardId())
.addValue("is_qa", finishedItem.getIsQa() ) .addValue("is_qa", finishedItem.getIsQa())
.addValue("stitched_item_id", finishedItem.getStitchedItemId() ) .addValue("stitched_item_id", finishedItem.getStitchedItemId())
.addValue("is_segregated", finishedItem.getIsSegregated() ) .addValue("is_segregated", finishedItem.getIsSegregated())
.addValue("qa_status", finishedItem.getQaStatus() ) .addValue("qa_status", finishedItem.getQaStatus())
.addValue("is_packed",finishedItem.isPackaging()); .addValue("is_packed", finishedItem.isPackaging());
return params; return params;
} }
// find // find
public FinishedItem find( long id ) { public FinishedItem find(long id) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", id ); params.addValue("id", id);
return namedParameterJdbcTemplate.query( SELECT_QUERY, params, new FinishedItemRowMapper() ) return namedParameterJdbcTemplate.query(SELECT_QUERY, params, new FinishedItemRowMapper())
.stream() .stream()
.findFirst() .findFirst()
.orElse( new FinishedItem() ); .orElse(new FinishedItem());
} }
// find all // find all
public List<FinishedItem> findAll() { public List<FinishedItem> findAll() {
return namedParameterJdbcTemplate.query( SELECT_ALL_QUERY, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_ALL_QUERY, new FinishedItemRowMapper());
} }
// save // save
public long save( FinishedItem finishedItem ) { public long save(FinishedItem finishedItem) {
KeyHolder keyHolder = new GeneratedKeyHolder(); KeyHolder keyHolder = new GeneratedKeyHolder();
MapSqlParameterSource params = prepareInsertQueryParams( finishedItem ); MapSqlParameterSource params = prepareInsertQueryParams(finishedItem);
namedParameterJdbcTemplate.update( INSERT_QUERY, params, keyHolder ); namedParameterJdbcTemplate.update(INSERT_QUERY, params, keyHolder);
return KeyHolderFunctions.getKey( finishedItem.getId(), keyHolder ); return KeyHolderFunctions.getKey(finishedItem.getId(), keyHolder);
} }
// save all // save all
public int[] saveAll( List<FinishedItem> finishedItems ) { public int[] saveAll(List<FinishedItem> finishedItems) {
List<MapSqlParameterSource> batchArgs = new ArrayList<>(); List<MapSqlParameterSource> batchArgs = new ArrayList<>();
for ( FinishedItem finishedItem: finishedItems ) { for (FinishedItem finishedItem : finishedItems) {
MapSqlParameterSource params = prepareInsertQueryParams( finishedItem ); MapSqlParameterSource params = prepareInsertQueryParams(finishedItem);
batchArgs.add( params ); batchArgs.add(params);
} }
return namedParameterJdbcTemplate.batchUpdate( INSERT_QUERY, batchArgs.toArray(new MapSqlParameterSource[finishedItems.size()]) ); return namedParameterJdbcTemplate.batchUpdate(INSERT_QUERY, batchArgs.toArray(new MapSqlParameterSource[finishedItems.size()]));
} }
// delete // delete
public boolean delete( long id ) { public boolean delete(long id) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "id", id ); params.addValue("id", id);
return namedParameterJdbcTemplate.update( DELETE_QUERY, params ) > 0; return namedParameterJdbcTemplate.update(DELETE_QUERY, params) > 0;
} }
public List<FinishedItem> findByLimit(Long count ){ public List<FinishedItem> findByLimit(Long count) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "limit",count ); params.addValue("limit", count);
return namedParameterJdbcTemplate.query( SELECT_BY_LIMIT , params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_BY_LIMIT, params, new FinishedItemRowMapper());
} }
public List<FinishedItem> findByQuery(String query ){ public List<FinishedItem> findByQuery(String query) {
return namedParameterJdbcTemplate.query( query, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(query, new FinishedItemRowMapper());
} }
public List<FinishedItem> findByIds(List<Long> ids ){ public List<FinishedItem> findByIds(List<Long> ids) {
if( ids == null || ids.isEmpty() ) return new ArrayList<>(); if (ids == null || ids.isEmpty()) return new ArrayList<>();
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("ids", ids ); params.addValue("ids", ids);
return namedParameterJdbcTemplate.query( SELECT_BY_IDS , params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_BY_IDS, params, new FinishedItemRowMapper());
} }
public List<FinishedItem> findByTerm( String term , boolean isSegregated ){ public List<FinishedItem> findByTerm(String term, boolean isQa) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("term", "%" + term + "%" ); params.addValue("term", "%" + term + "%");
params.addValue("is_segregated", isSegregated ); params.addValue("is_qa", isQa);
return namedParameterJdbcTemplate.query( SELECT_BY_TERM , params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_BY_TERM, params, new FinishedItemRowMapper());
} }
public List<FinishedItem> findByTermForPackaging( String term , boolean isSegregated ){ public List<FinishedItem> findByTermForPackaging(String term, boolean isSegregated) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("term", "%" + term + "%" ); params.addValue("term", "%" + term + "%");
params.addValue("is_segregated", isSegregated ); params.addValue("is_segregated", isSegregated);
return namedParameterJdbcTemplate.query( SELECT_BY_TERM_FOR_PACKAGING , params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_BY_TERM_FOR_PACKAGING, params, new FinishedItemRowMapper());
} }
// find By job card Id // find By job card Id
public List<FinishedItem> findByJobCardId(long jobCardId ) { public List<FinishedItem> findByJobCardId(long jobCardId) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue( "job_card_id", jobCardId ); params.addValue("job_card_id", jobCardId);
return namedParameterJdbcTemplate.query(SELECT_QUERY_BY_JOB_CARD, params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_QUERY_BY_JOB_CARD, params, new FinishedItemRowMapper());
} }
public FinishedItem findByStitchedItem( long stitchedItemId ){ public FinishedItem findByStitchedItem(long stitchedItemId) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("stitched_item_id", stitchedItemId ); params.addValue("stitched_item_id", stitchedItemId);
return namedParameterJdbcTemplate.query( SELECT_BY_STITCHED_ITEM_ID , params, new FinishedItemRowMapper() ) return namedParameterJdbcTemplate.query(SELECT_BY_STITCHED_ITEM_ID, params, new FinishedItemRowMapper())
.stream() .stream()
.findFirst() .findFirst()
.orElse( null ); .orElse(null);
} }
public HashMap<Long, Long> findTotalFinishedItems(List<Long> itemIds, long jobCardId) { public HashMap<Long, Long> findTotalFinishedItems(List<Long> itemIds, long jobCardId) {
HashMap<Long, Long> totalCounts = new HashMap<>(); HashMap<Long, Long> totalCounts = new HashMap<>();
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
for (long id : itemIds) { for (long id : itemIds) {
params.addValue("job_card_id", jobCardId); params.addValue("job_card_id", jobCardId);
params.addValue("item_id", id); params.addValue("item_id", id);
Long total = namedParameterJdbcTemplate.queryForObject(FIND_TOTAL_COUNT, params, Long.class); Long total = namedParameterJdbcTemplate.queryForObject(FIND_TOTAL_COUNT, params, Long.class);
if (total != null) { if (total != null) {
totalCounts.put(id, total); totalCounts.put(id, total);
} }
} }
return totalCounts; return totalCounts;
} }
public List<FinishedItem> findByStitchedItemIds( List<Long> stitchedItemIds ){ public List<FinishedItem> findByStitchedItemIds(List<Long> stitchedItemIds) {
if( stitchedItemIds == null || stitchedItemIds.isEmpty() ) return new ArrayList<>(); if (stitchedItemIds == null || stitchedItemIds.isEmpty()) return new ArrayList<>();
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("stitched_item_ids", stitchedItemIds ); params.addValue("stitched_item_ids", stitchedItemIds);
return namedParameterJdbcTemplate.query( SELECT_BY_STITCHED_ITEM_IDS, params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_BY_STITCHED_ITEM_IDS, params, new FinishedItemRowMapper());
} }
public List<StitchingOfflineItem> findByBarcodeAndApprovedStatus( List<StitchingOfflineItem> stitchingOfflineItems ){ public List<StitchingOfflineItem> findByBarcodeAndApprovedStatus(List<StitchingOfflineItem> stitchingOfflineItems) {
List<StitchingOfflineItem> items = new ArrayList<>(); List<StitchingOfflineItem> items = new ArrayList<>();
for (StitchingOfflineItem item : stitchingOfflineItems){ for (StitchingOfflineItem item : stitchingOfflineItems) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("barcode", item.getBarcode() ); params.addValue("barcode", item.getBarcode());
boolean check =Boolean.TRUE.equals(namedParameterJdbcTemplate.queryForObject( SELECT_QUERY_BY_BARCODE_QA_STATUS, params, Boolean.class )); boolean check = Boolean.TRUE.equals(namedParameterJdbcTemplate.queryForObject(SELECT_QUERY_BY_BARCODE_QA_STATUS, params, Boolean.class));
if(!check){ if (!check) {
items.add(item); items.add(item);
} }
} }
return items; return items;
} }
public Long calculateTotalFinishItem( long jobCardId ){ public Long calculateTotalFinishItem(long jobCardId) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("job_card_id", jobCardId ); params.addValue("job_card_id", jobCardId);
Long count = namedParameterJdbcTemplate.queryForObject(COUNT_TOTAL_FINISH_ITEM, params, Long.class); Long count = namedParameterJdbcTemplate.queryForObject(COUNT_TOTAL_FINISH_ITEM, params, Long.class);
return count != null ? count : 0; return count != null ? count : 0;
} }
public List<FinishedItem> calculateTotalFinishItem( long jobCardId, String startDate, String endDate ){ public List<FinishedItem> calculateTotalFinishItem(long jobCardId, String startDate, String endDate) {
MapSqlParameterSource params = new MapSqlParameterSource(); MapSqlParameterSource params = new MapSqlParameterSource();
params.addValue("job_card_id", jobCardId ); params.addValue("job_card_id", jobCardId);
params.addValue( "start_date", startDate ); params.addValue("start_date", startDate);
params.addValue( "end_date", endDate ); params.addValue("end_date", endDate);
return namedParameterJdbcTemplate.query( SELECT_BY_JOB_CARD_AND_DATE, params, new FinishedItemRowMapper() ); return namedParameterJdbcTemplate.query(SELECT_BY_JOB_CARD_AND_DATE, params, new FinishedItemRowMapper());
} }
} }

View File

@ -4,6 +4,8 @@ import java.util.List;
public class FinishedItemWrapper { public class FinishedItemWrapper {
private String qaStatus;
private List<FinishedItem> items; private List<FinishedItem> items;
public List<FinishedItem> getItems() { public List<FinishedItem> getItems() {
@ -14,6 +16,14 @@ public class FinishedItemWrapper {
this.items = items; this.items = items;
} }
public String getQaStatus() {
return qaStatus;
}
public void setQaStatus(String qaStatus) {
this.qaStatus = qaStatus;
}
@Override @Override
public String toString() { public String toString() {
return "FinishedItemWrapper{" + return "FinishedItemWrapper{" +

View File

@ -1,12 +1,20 @@
package com.utopiaindustries.model.ctp; package com.utopiaindustries.model.ctp;
import java.util.*; import java.util.*;
public class StitchedItemWrapper { public class StitchedItemWrapper {
private String qaStatus;
private List<StitchingOfflineItem> items; private List<StitchingOfflineItem> items;
private Long finishedAccountId; private Long finishedAccountId;
public String getQaStatus() {
return qaStatus;
}
public void setQaStatus(String qaStatus) {
this.qaStatus = qaStatus;
}
public List<StitchingOfflineItem> getItems() { public List<StitchingOfflineItem> getItems() {
return items; return items;

View File

@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RestController;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping( "/rest/finished-items" ) @RequestMapping("/rest/finished-items")
public class FinishedItemRestController { public class FinishedItemRestController {
private final FinishedItemDAO finishedItemDAO; private final FinishedItemDAO finishedItemDAO;
@ -19,14 +19,15 @@ public class FinishedItemRestController {
this.finishedItemDAO = finishedItemDAO; this.finishedItemDAO = finishedItemDAO;
} }
@GetMapping( "/search" ) @GetMapping("/search")
public List<FinishedItem> searchFinishedItems(@RequestParam( "term") String term, public List<FinishedItem> searchFinishedItems(@RequestParam("term") String term,
@RequestParam( "is-segregated") boolean isSegregated ){ @RequestParam("is-segregated") boolean isSegregated) {
return finishedItemDAO.findByTerm( term, isSegregated ); return finishedItemDAO.findByTerm(term, true);
} }
@GetMapping( "/search-packaging" )
public List<FinishedItem> searchFinishedItemsForPackaging(@RequestParam( "term") String term, @GetMapping("/search-packaging")
@RequestParam( "is-segregated") boolean isSegregated ){ public List<FinishedItem> searchFinishedItemsForPackaging(@RequestParam("term") String term,
return finishedItemDAO.findByTermForPackaging( term, true ); @RequestParam("is-segregated") boolean isSegregated) {
return finishedItemDAO.findByTermForPackaging(term, true);
} }
} }

View File

@ -44,55 +44,55 @@ public class InventoryService {
this.packagingItemsDAO = packagingItemsDAO; this.packagingItemsDAO = packagingItemsDAO;
} }
private void updateJobCardInventoryStatus( JobCard card ){ private void updateJobCardInventoryStatus(JobCard card) {
List<JobCardItem> items = jobCardItemDAO.findByCardId( card.getId( ) ); List<JobCardItem> items = jobCardItemDAO.findByCardId(card.getId());
for( JobCardItem item : items ){ for (JobCardItem item : items) {
// check if item is received // check if item is received
if( item.getActualProduction( ) == null || item.getActualProduction( ).compareTo( BigDecimal.ZERO ) == 0 ){ if (item.getActualProduction() == null || item.getActualProduction().compareTo(BigDecimal.ZERO) == 0) {
return; return;
} }
} }
card.setInventoryStatus( JobCard.InventoryStatus.RECEIVED.name( ) ); card.setInventoryStatus(JobCard.InventoryStatus.RECEIVED.name());
jobCardDAO.save( card ); jobCardDAO.save(card);
} }
/* /*
* receive inv from job card * receive inv from job card
* */ * */
@Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
public void receiveJobCardInventory( long jobCardId, JobCardWrapper jobCardWrapper ) { public void receiveJobCardInventory(long jobCardId, JobCardWrapper jobCardWrapper) {
if ( jobCardId == 0 || jobCardWrapper.getItems( ) == null || jobCardWrapper.getItems( ).isEmpty( ) ) { if (jobCardId == 0 || jobCardWrapper.getItems() == null || jobCardWrapper.getItems().isEmpty()) {
throw new RuntimeException( " JobCard can`t be empty"); throw new RuntimeException(" JobCard can`t be empty");
} }
JobCard jobCard = jobCardDAO.find( jobCardId ); JobCard jobCard = jobCardDAO.find(jobCardId);
// get job cad items // get job cad items
List<JobCardItemWrapper> jobCardItemWrappers = jobCardWrapper.getItems( ); List<JobCardItemWrapper> jobCardItemWrappers = jobCardWrapper.getItems();
List<Long> jobCardItemWrapperIds = jobCardItemWrappers.stream( ) List<Long> jobCardItemWrapperIds = jobCardItemWrappers.stream()
.map( JobCardItemWrapper::getJobCardItemId ) .map(JobCardItemWrapper::getJobCardItemId)
.collect( Collectors.toList( ) ); .collect(Collectors.toList());
Map<Long,BigDecimal> jobCardItemIdToActualProdMap = jobCardItemWrappers.stream( ) Map<Long, BigDecimal> jobCardItemIdToActualProdMap = jobCardItemWrappers.stream()
.collect( Collectors.toMap( JobCardItemWrapper::getJobCardItemId, JobCardItemWrapper::getActualProduction ) ); .collect(Collectors.toMap(JobCardItemWrapper::getJobCardItemId, JobCardItemWrapper::getActualProduction));
List<JobCardItem> items = jobCardItemDAO.findByIds( jobCardItemWrapperIds ); List<JobCardItem> items = jobCardItemDAO.findByIds(jobCardItemWrapperIds);
if ( items != null && !items.isEmpty( ) ) { if (items != null && !items.isEmpty()) {
// get job card item ids // get job card item ids
List<Long> jobCardItemIds = items.stream( ) List<Long> jobCardItemIds = items.stream()
.map( JobCardItem::getId) .map(JobCardItem::getId)
.collect( Collectors.toList( )); .collect(Collectors.toList());
// save updated cut pieces // save updated cut pieces
List<CutPiece> cutPieces = jobCardItemWrappers.stream( ) List<CutPiece> cutPieces = jobCardItemWrappers.stream()
.flatMap( wrapper -> wrapper.getPieces( ).stream( ) ) .flatMap(wrapper -> wrapper.getPieces().stream())
.collect( Collectors.toList( ) ); .collect(Collectors.toList());
cutPieceDAO.saveAll( cutPieces ); cutPieceDAO.saveAll(cutPieces);
Map<Long, List<CutPiece>> piecesMap = cutPieceDAO.findByJobCardItemIds( jobCardItemIds) Map<Long, List<CutPiece>> piecesMap = cutPieceDAO.findByJobCardItemIds(jobCardItemIds)
.stream( ) .stream()
.collect( Collectors.groupingBy( CutPiece::getJobCardItemId)); .collect(Collectors.groupingBy(CutPiece::getJobCardItemId));
for ( JobCardItem jobCardItem : items) { for (JobCardItem jobCardItem : items) {
int quantity = jobCardItemWrappers.stream() int quantity = jobCardItemWrappers.stream()
.filter(e -> e.getJobCardItemId() == jobCardItem.getId()) .filter(e -> e.getJobCardItemId() == jobCardItem.getId())
@ -112,32 +112,32 @@ public class InventoryService {
.findFirst() .findFirst()
.orElse(BigDecimal.ZERO); .orElse(BigDecimal.ZERO);
List<Bundle> bundles = createBundles( jobCardItem,quantity,jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) ); List<Bundle> bundles = createBundles(jobCardItem, quantity, jobCardItemIdToActualProdMap.getOrDefault(jobCardItem.getId(), BigDecimal.ZERO));
// create transactions // create transactions
createTransactions( bundles, jobCardItem.getAccountId( ), InventoryArtifactType.BUNDLE.name( )); createTransactions(bundles, jobCardItem.getAccountId(), InventoryArtifactType.BUNDLE.name());
jobCardItem.setActualProduction( jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ), BigDecimal.ZERO ).add(jobCardItem.getActualProduction()) ); jobCardItem.setActualProduction(jobCardItemIdToActualProdMap.getOrDefault(jobCardItem.getId(), BigDecimal.ZERO).add(jobCardItem.getActualProduction()));
jobCardItem.setComplete(cuttingComplete); jobCardItem.setComplete(cuttingComplete);
} }
// update items with quantity // update items with quantity
jobCardItemDAO.saveAll( items ); jobCardItemDAO.saveAll(items);
// update job card inv status // update job card inv status
if(jobCardItemDAO.checkAllItemsComplete(jobCardId,jobCardItemIds)) { if (jobCardItemDAO.checkAllItemsComplete(jobCardId, jobCardItemIds)) {
updateJobCardInventoryStatus(jobCard); updateJobCardInventoryStatus(jobCard);
} }
} else { } else {
throw new RuntimeException( "Items Not found in Job Card"); throw new RuntimeException("Items Not found in Job Card");
} }
} }
/* /*
* t create transactions * t create transactions
* */ * */
private void createTransactions( List<? extends InventoryArtifact> artifacts, long accountId, String parentDocumentType) { private void createTransactions(List<? extends InventoryArtifact> artifacts, long accountId, String parentDocumentType) {
if ( !artifacts.isEmpty( )) { if (!artifacts.isEmpty()) {
InventoryTransaction transaction = createInventoryTransaction( "Transaction Against " + parentDocumentType); InventoryTransaction transaction = createInventoryTransaction("Transaction Against " + parentDocumentType);
for ( InventoryArtifact artifact : artifacts) { for (InventoryArtifact artifact : artifacts) {
InventoryTransactionLeg leg = createInventoryTransactionLeg( transaction, artifact, accountId, InventoryTransactionLeg.Type.IN.name( ), parentDocumentType ); InventoryTransactionLeg leg = createInventoryTransactionLeg(transaction, artifact, accountId, InventoryTransactionLeg.Type.IN.name(), parentDocumentType);
} }
} }
} }
@ -146,93 +146,93 @@ public class InventoryService {
/* /*
* create and save transaction * create and save transaction
* */ * */
private InventoryTransaction createInventoryTransaction( String notes) { private InventoryTransaction createInventoryTransaction(String notes) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
InventoryTransaction transaction = new InventoryTransaction( ); InventoryTransaction transaction = new InventoryTransaction();
transaction.setGeneratedBy( authentication.getName( )); transaction.setGeneratedBy(authentication.getName());
transaction.setTransactionDateTime( LocalDateTime.now( )); transaction.setTransactionDateTime(LocalDateTime.now());
transaction.setNotes( notes); transaction.setNotes(notes);
transaction.setId( inventoryTransactionDAO.save( transaction)); transaction.setId(inventoryTransactionDAO.save(transaction));
return transaction; return transaction;
} }
/* /*
* create and save inventory transaction * create and save inventory transaction
* */ * */
private InventoryTransactionLeg createInventoryTransactionLeg( InventoryTransaction transaction, private InventoryTransactionLeg createInventoryTransactionLeg(InventoryTransaction transaction,
InventoryArtifact artifact, InventoryArtifact artifact,
long accountId, long accountId,
String transactionType, String transactionType,
String parentDocumentType) { String parentDocumentType) {
InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg( ); InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg();
inventoryTransactionLeg.setTransactionId( transaction.getId( )); inventoryTransactionLeg.setTransactionId(transaction.getId());
inventoryTransactionLeg.setType( transactionType); inventoryTransactionLeg.setType(transactionType);
inventoryTransactionLeg.setQuantity( BigDecimal.valueOf( 1L)); inventoryTransactionLeg.setQuantity(BigDecimal.valueOf(1L));
inventoryTransactionLeg.setAccountId( ( int) accountId); inventoryTransactionLeg.setAccountId((int) accountId);
inventoryTransactionLeg.setItemId( artifact.getItemId( )); inventoryTransactionLeg.setItemId(artifact.getItemId());
inventoryTransactionLeg.setSku( artifact.getSku( )); inventoryTransactionLeg.setSku(artifact.getSku());
inventoryTransactionLeg.setParentDocumentType( parentDocumentType); inventoryTransactionLeg.setParentDocumentType(parentDocumentType);
inventoryTransactionLeg.setParentDocumentId( artifact.getId( )); inventoryTransactionLeg.setParentDocumentId(artifact.getId());
inventoryTransactionLeg.setParentDocumentPieceType( artifact.getType( )); inventoryTransactionLeg.setParentDocumentPieceType(artifact.getType());
inventoryTransactionLeg.setTransactionLegDateTime( LocalDateTime.now( )); inventoryTransactionLeg.setTransactionLegDateTime(LocalDateTime.now());
inventoryTransactionLeg.setJobCardId(artifact.getJobCardId()); inventoryTransactionLeg.setJobCardId(artifact.getJobCardId());
// set balance // 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( ))) { if (transactionType.equalsIgnoreCase(InventoryTransactionLeg.Type.IN.name())) {
initialBalance = initialBalance.add( inventoryTransactionLeg.getQuantity( )); initialBalance = initialBalance.add(inventoryTransactionLeg.getQuantity());
}else if(transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.OUT.name( ))) { } else if (transactionType.equalsIgnoreCase(InventoryTransactionLeg.Type.OUT.name())) {
if (inventoryTransactionLeg.getQuantity().equals(BigDecimal.ZERO)) { if (inventoryTransactionLeg.getQuantity().equals(BigDecimal.ZERO)) {
initialBalance = BigDecimal.ZERO; initialBalance = BigDecimal.ZERO;
} else { } else {
initialBalance = initialBalance.subtract(inventoryTransactionLeg.getQuantity()); initialBalance = initialBalance.subtract(inventoryTransactionLeg.getQuantity());
} }
} }
inventoryTransactionLeg.setBalance( initialBalance); inventoryTransactionLeg.setBalance(initialBalance);
inventoryTransactionLeg.setId( inventoryTransactionLegDAO.save( inventoryTransactionLeg)); inventoryTransactionLeg.setId(inventoryTransactionLegDAO.save(inventoryTransactionLeg));
return inventoryTransactionLeg; return inventoryTransactionLeg;
} }
// calculate balance // 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 // find the last transaction leg of the current account Id with itemId
InventoryTransactionLeg lastTransactionLeg = inventoryTransactionLegDAO.findLastByAccountIdAndItemIdAndParentType( accountId, itemId, parentType, pieceType); InventoryTransactionLeg lastTransactionLeg = inventoryTransactionLegDAO.findLastByAccountIdAndItemIdAndParentType(accountId, itemId, parentType, pieceType);
if ( lastTransactionLeg.getBalance( ) != null) { if (lastTransactionLeg.getBalance() != null) {
return lastTransactionLeg.getBalance( ); return lastTransactionLeg.getBalance();
} }
return BigDecimal.ZERO; return BigDecimal.ZERO;
} }
// create bundles from cut pieces // create bundles from cut pieces
private List<Bundle> createBundles( JobCardItem jobCardItem, private List<Bundle> createBundles(JobCardItem jobCardItem,
int perBundleWrap, BigDecimal value ) { int perBundleWrap, BigDecimal value) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if ( value != null && !value.equals(BigDecimal.ZERO)) { if (value != null && !value.equals(BigDecimal.ZERO)) {
List<Bundle> bundles = new ArrayList<>( ); List<Bundle> bundles = new ArrayList<>();
int quantity = value.intValue(); int quantity = value.intValue();
int batchSize = perBundleWrap; int batchSize = perBundleWrap;
int iterations = (int) Math.ceil((double) quantity / batchSize); int iterations = (int) Math.ceil((double) quantity / batchSize);
for (int i = 0; i < iterations; i++) { for (int i = 0; i < iterations; i++) {
int start = i * batchSize + 1; // Start index int start = i * batchSize + 1; // Start index
int end = Math.min((i + 1) * batchSize, quantity); // Last index int end = Math.min((i + 1) * batchSize, quantity); // Last index
int perBundleQuantity = end - start + 1; int perBundleQuantity = end - start + 1;
Bundle bundle = new Bundle( ); Bundle bundle = new Bundle();
bundle.setItemId( jobCardItem.getItemId( )); bundle.setItemId(jobCardItem.getItemId());
bundle.setSku( jobCardItem.getSku( )); bundle.setSku(jobCardItem.getSku());
bundle.setJobCardId( jobCardItem.getJobCardId( ) ); bundle.setJobCardId(jobCardItem.getJobCardId());
bundle.setWrapQuantity( BigDecimal.valueOf(perBundleQuantity)); bundle.setWrapQuantity(BigDecimal.valueOf(perBundleQuantity));
bundle.setType( "BUNDLE"); bundle.setType("BUNDLE");
bundle.setCreatedAt( LocalDateTime.now( )); bundle.setCreatedAt(LocalDateTime.now());
bundle.setCreatedBy( authentication.getName( )); bundle.setCreatedBy(authentication.getName());
bundles.add( bundle); bundles.add(bundle);
bundle.setId( bundleDAO.save( bundle)); bundle.setId(bundleDAO.save(bundle));
bundle.setBarcode( cryptographyService.generateRandomString( 15)); bundle.setBarcode(cryptographyService.generateRandomString(15));
// save again after barcode generation // save again after barcode generation
bundle.setId( bundleDAO.save( bundle)); bundle.setId(bundleDAO.save(bundle));
} }
// for ( Map.Entry<JobCardItem, List<CutPiece>> entry : jobCardItemPieces ) { // for ( Map.Entry<JobCardItem, List<CutPiece>> entry : jobCardItemPieces ) {
// JobCardItem key = entry.getKey( ); // JobCardItem key = entry.getKey( );
@ -242,87 +242,87 @@ public class InventoryService {
// } // }
return bundles; return bundles;
} }
return new ArrayList<>( ); return new ArrayList<>();
} }
/* /*
* receive inventory from master barcode * receive inventory from master barcode
* */ * */
@Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
public void receiveInventoryFromMasterBarcode( long masterId, long toAccount) { public void receiveInventoryFromMasterBarcode(long masterId, long toAccount) {
if ( masterId == 0 || toAccount == 0) { if (masterId == 0 || toAccount == 0) {
throw new RuntimeException( "Master Barcode | Account can`t be empty"); 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 // find bundles from master barcode
List<Bundle> bundles = bundleDAO.findByMasterId( masterId); List<Bundle> bundles = bundleDAO.findByMasterId(masterId);
if ( bundles != null && !bundles.isEmpty( )) { if (bundles != null && !bundles.isEmpty()) {
// bundle ids // bundle ids
List<Long> bundleIds = bundles.stream( ).map( Bundle::getId).collect( Collectors.toList( )); List<Long> bundleIds = bundles.stream().map(Bundle::getId).collect(Collectors.toList());
Map<Long, InventoryTransactionLeg> lastBundleIdInTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastBundleIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), bundleIds, InventoryArtifactType.BUNDLE.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), bundleIds, InventoryArtifactType.BUNDLE.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
// create Transaction // create Transaction
InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Cutting to Stitching"); InventoryTransaction transaction = createInventoryTransaction("Against Movement from Cutting to Stitching");
inventoryTransactionDAO.save( transaction); inventoryTransactionDAO.save(transaction);
// create transaction legs // create transaction legs
for ( Bundle bundle : bundles) { for (Bundle bundle : bundles) {
InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( bundle.getId( ), null); InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(bundle.getId(), null);
if ( lastInvTransaction != null) { if (lastInvTransaction != null) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId( ); long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg( transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.BUNDLE.name( )); createInventoryTransactionLeg(transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.BUNDLE.name());
// IN // IN
bundle.setType("BUNDLE"); 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 // update status
masterBundle.setIsReceived( true); masterBundle.setIsReceived(true);
masterBundle.setAccountId(toAccount); masterBundle.setAccountId(toAccount);
masterBundleDAO.save( masterBundle); masterBundleDAO.save(masterBundle);
} }
} }
private void validateItems( List<JobCardItem> cardItems) { private void validateItems(List<JobCardItem> cardItems) {
if ( cardItems == null || cardItems.isEmpty( )) { if (cardItems == null || cardItems.isEmpty()) {
throw new RuntimeException( "Item cant be Empty | null"); throw new RuntimeException("Item cant be Empty | null");
} }
for ( JobCardItem jobCardItem : cardItems) { for (JobCardItem jobCardItem : cardItems) {
if( jobCardItem.getTotalProduction() != null ){ if (jobCardItem.getTotalProduction() != null) {
int finalQuantity = jobCardItem.getActualProduction( ).compareTo( jobCardItem.getTotalProduction( ).add( jobCardItem.getProduction( ))); int finalQuantity = jobCardItem.getActualProduction().compareTo(jobCardItem.getTotalProduction().add(jobCardItem.getProduction()));
if ( finalQuantity < 0) { if (finalQuantity < 0) {
throw new RuntimeException( " Items cant be generated because it exceeds from limit of expected Production"); 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<JobCardItem> jobCardItems) { List<JobCardItem> jobCardItems) {
if ( jobCardItems != null && !jobCardItems.isEmpty( ) ) { if (jobCardItems != null && !jobCardItems.isEmpty()) {
List<Long> itemIds = jobCardItems.stream( ) List<Long> itemIds = jobCardItems.stream()
.filter( JobCardItem::getIsSelected ) .filter(JobCardItem::getIsSelected)
.map( JobCardItem::getItemId).collect( Collectors.toList( )); .map(JobCardItem::getItemId).collect(Collectors.toList());
List<Bundle> bundles = bundleDAO.findByItemIdsAndCardId( itemIds, jobCardId); List<Bundle> bundles = bundleDAO.findByItemIdsAndCardId(itemIds, jobCardId);
List<Long> masterBundleIds = bundles.stream( ).map( Bundle::getMasterBundleId).collect( Collectors.toList( )); List<Long> masterBundleIds = bundles.stream().map(Bundle::getMasterBundleId).collect(Collectors.toList());
Map<Long, MasterBundle> idToMasterBundleMap = masterBundleDAO.findByIds( masterBundleIds)
.stream( )
.collect( Collectors.toMap( MasterBundle::getId, Function.identity( )));
for ( Bundle bundle : bundles) { Map<Long, MasterBundle> idToMasterBundleMap = masterBundleDAO.findByIds(masterBundleIds)
.stream()
.collect(Collectors.toMap(MasterBundle::getId, Function.identity()));
for (Bundle bundle : bundles) {
// check all bundles are received // check all bundles are received
MasterBundle masterBundle = idToMasterBundleMap.getOrDefault( bundle.getMasterBundleId( ), null); MasterBundle masterBundle = idToMasterBundleMap.getOrDefault(bundle.getMasterBundleId(), null);
if ( masterBundle == null || ! masterBundle.getIsReceived( ) ) { if (masterBundle == null || !masterBundle.getIsReceived()) {
throw new RuntimeException( "Please Receive Bundles Against Master Bundles First to Create Finished Item"); 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 * create finished items from master bundles
* */ * */
@Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
public void createStitchingOfflineItemsFromJobCard( BundleWrapper wrapper) { public void createStitchingOfflineItemsFromJobCard(BundleWrapper wrapper) {
List<JobCardItem> updatedItems = new ArrayList<>(); List<JobCardItem> updatedItems = new ArrayList<>();
List<Bundle> updateBundles = new ArrayList<>(); List<Bundle> updateBundles = new ArrayList<>();
JobCard jobCard = null; JobCard jobCard = null;
@ -349,17 +349,17 @@ public class InventoryService {
.collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
for (Bundle subBundle : wrapper.getBundles()) { for (Bundle subBundle : wrapper.getBundles()) {
long accountId = masterBundleDAO.find(subBundle.getMasterBundleId()).getAccountId(); 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()); Bundle bundle = bundleDAO.find(subBundle.getId());
jobCard = jobCardDAO.find(subBundle.getJobCardId()); 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(); 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(); BigDecimal previousTotalProduction = jobCardItem.getTotalProduction() == null ? BigDecimal.ZERO : jobCardItem.getTotalProduction();
InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(subBundle.getId(), null); InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(subBundle.getId(), null);
if (lastInvTransaction != null ) { if (lastInvTransaction != null) {
if (wrapQuantity == production + subBundle.getCurrentProduction().longValue()) { if (wrapQuantity == production + subBundle.getCurrentProduction().longValue()) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId(); long fromAccount = lastInvTransaction.getAccountId();
@ -367,7 +367,7 @@ public class InventoryService {
} }
} }
// create stitchingOfflineItems items // create stitchingOfflineItems items
List<StitchingOfflineItem> stitchingOfflineItems = createStitchingOfflineItems(subBundle.getCurrentProduction(),jobCardItem,subBundle.getId()); List<StitchingOfflineItem> stitchingOfflineItems = createStitchingOfflineItems(subBundle.getCurrentProduction(), jobCardItem, subBundle.getId());
// create IN Transactions of Finished Items into account // create IN Transactions of Finished Items into account
createTransactions(stitchingOfflineItems, accountId, InventoryArtifactType.STITCHING_OFFLINE.name()); createTransactions(stitchingOfflineItems, accountId, InventoryArtifactType.STITCHING_OFFLINE.name());
@ -385,24 +385,24 @@ public class InventoryService {
/* /*
* create finished items * create finished items
* */ * */
public List<StitchingOfflineItem> createStitchingOfflineItems( BigDecimal totalItem, JobCardItem jobCardItem,long bundleId) { public List<StitchingOfflineItem> createStitchingOfflineItems(BigDecimal totalItem, JobCardItem jobCardItem, long bundleId) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
List<StitchingOfflineItem> items = new ArrayList<>( ); List<StitchingOfflineItem> items = new ArrayList<>();
if ( jobCardItem != null) { if (jobCardItem != null) {
for ( int i = 1; i <= totalItem.intValue( ); i++) { for (int i = 1; i <= totalItem.intValue(); i++) {
StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem( ); StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem();
stitchingOfflineItem.setCreatedAt( LocalDateTime.now( )); stitchingOfflineItem.setCreatedAt(LocalDateTime.now());
stitchingOfflineItem.setCreatedBy( authentication.getName( )); stitchingOfflineItem.setCreatedBy(authentication.getName());
stitchingOfflineItem.setItemId( jobCardItem.getItemId( )); stitchingOfflineItem.setItemId(jobCardItem.getItemId());
stitchingOfflineItem.setSku( jobCardItem.getSku( )); stitchingOfflineItem.setSku(jobCardItem.getSku());
stitchingOfflineItem.setBundleId(bundleId); stitchingOfflineItem.setBundleId(bundleId);
stitchingOfflineItem.setJobCardId( jobCardItem.getJobCardId( )); stitchingOfflineItem.setJobCardId(jobCardItem.getJobCardId());
stitchingOfflineItem.setIsQa( false ); stitchingOfflineItem.setIsQa(false);
long id = stitchingOfflineItemDAO.save( stitchingOfflineItem); long id = stitchingOfflineItemDAO.save(stitchingOfflineItem);
stitchingOfflineItem.setId( id); stitchingOfflineItem.setId(id);
stitchingOfflineItem.setBarcode( cryptographyService.generateRandomString( 15)); stitchingOfflineItem.setBarcode(cryptographyService.generateRandomString(15));
stitchingOfflineItemDAO.save( stitchingOfflineItem); stitchingOfflineItemDAO.save(stitchingOfflineItem);
items.add( stitchingOfflineItem); items.add(stitchingOfflineItem);
} }
} }
return items; return items;
@ -411,51 +411,51 @@ public class InventoryService {
/* /*
* find transactions by account id * find transactions by account id
* */ * */
public List<InventoryTransactionLeg> findTransactionByAccountId( long accountId) { public List<InventoryTransactionLeg> findTransactionByAccountId(long accountId) {
List<InventoryTransactionLeg> legs = inventoryTransactionLegDAO.findByAccountId( accountId); List<InventoryTransactionLeg> legs = inventoryTransactionLegDAO.findByAccountId(accountId);
List<Long> tIds = legs.stream( ).map( InventoryTransactionLeg::getTransactionId).collect( Collectors.toList( )); List<Long> tIds = legs.stream().map(InventoryTransactionLeg::getTransactionId).collect(Collectors.toList());
Map<Long, InventoryTransaction> idToTransactioMap = inventoryTransactionDAO.findByIds( tIds).stream( ).collect( Collectors.toMap( InventoryTransaction::getId, Function.identity( ))); Map<Long, InventoryTransaction> idToTransactioMap = inventoryTransactionDAO.findByIds(tIds).stream().collect(Collectors.toMap(InventoryTransaction::getId, Function.identity()));
legs.forEach( leg -> leg.setTransaction( idToTransactioMap.get( leg.getTransactionId( )))); legs.forEach(leg -> leg.setTransaction(idToTransactioMap.get(leg.getTransactionId())));
return legs; return legs;
} }
/* /*
* *
* */ * */
@Transactional( rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void markFinishedItemsApproved( List<Long> fItemIds, long toAccount) { public void markFinishedItemsApproved(List<Long> fItemIds, long toAccount) {
if ( fItemIds.isEmpty( ) || toAccount == 0) { if (fItemIds.isEmpty() || toAccount == 0) {
throw new RuntimeException( "Finished Item Ids | Account can`t be empty"); throw new RuntimeException("Finished Item Ids | Account can`t be empty");
} }
List<FinishedItem> finishedItems = finishedItemDAO.findByIds( fItemIds); List<FinishedItem> finishedItems = finishedItemDAO.findByIds(fItemIds);
if ( finishedItems != null && !finishedItems.isEmpty( )) { if (finishedItems != null && !finishedItems.isEmpty()) {
// bundle ids // bundle ids
List<Long> finishedItemIds = finishedItems.stream( ).map( FinishedItem::getId).collect( Collectors.toList( )); List<Long> finishedItemIds = finishedItems.stream().map(FinishedItem::getId).collect(Collectors.toList());
Map<Long, InventoryTransactionLeg> lastBundleIdInTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastBundleIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
// create Transaction // create Transaction
InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Stitching to Packaging After QA"); InventoryTransaction transaction = createInventoryTransaction("Against Movement from Stitching to Packaging After QA");
inventoryTransactionDAO.save( transaction); inventoryTransactionDAO.save(transaction);
// create transaction legs // create transaction legs
for ( FinishedItem finishedItem : finishedItems) { for (FinishedItem finishedItem : finishedItems) {
InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(finishedItem.getId(), null);
if ( lastInvTransaction != null) { if (lastInvTransaction != null) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId( ); long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCHING_OFFLINE.name());
// IN // 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 * generate finished items against stitched items
* */ * */
@Transactional( rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void createFinishedItemsAgainstStitchedItems( StitchedItemWrapper wrapper ) { public void createFinishedItemsAgainstStitchedItems(StitchedItemWrapper wrapper, String qaStatus) {
if ( wrapper.getItems( ) != null && wrapper.getFinishedAccountId( ) != 0) { if (wrapper.getItems() != null && wrapper.getFinishedAccountId() != 0) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
List<StitchingOfflineItem> stitchingOfflineItems = wrapper.getItems( ); List<StitchingOfflineItem> stitchingOfflineItems = wrapper.getItems();
List<StitchingOfflineItem> updatedStitchedItems = new ArrayList<>( ); List<StitchingOfflineItem> updatedStitchedItems = new ArrayList<>();
List<FinishedItem> finishedItems = new ArrayList<>( ); List<FinishedItem> finishedItems = new ArrayList<>();
List<FinishedItem> finishedItemsForUlter = new ArrayList<>();
List<Long> stitchedItemIds = stitchingOfflineItems.stream( ) List<Long> stitchedItemIds = stitchingOfflineItems.stream()
.map( StitchingOfflineItem::getId) .map(StitchingOfflineItem::getId)
.collect( Collectors.toList( )); .collect(Collectors.toList());
Map<Long, InventoryTransactionLeg> lastStitchedIdInTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastStitchedIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
// get finished items from stitched items if exists // get finished items from stitched items if exists
List<Long> preCreatedFinishedItemIds = finishedItemDAO.findByStitchedItemIds( stitchedItemIds ).stream( ). List<Long> preCreatedFinishedItemIds = finishedItemDAO.findByStitchedItemIds(stitchedItemIds).stream().
map( FinishedItem::getId ).collect( Collectors.toList( )); map(FinishedItem::getId).collect(Collectors.toList());
Map<Long, InventoryTransactionLeg> lastFinishedItemInTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastFinishedItemInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), preCreatedFinishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), preCreatedFinishedItemIds, InventoryArtifactType.FINISHED_ITEM.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .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 // generate FI for SI
for ( StitchingOfflineItem stitchingOfflineItem : stitchingOfflineItems) { for (StitchingOfflineItem stitchingOfflineItem : stitchingOfflineItems) {
if ( stitchingOfflineItem.getQaStatus( ).equalsIgnoreCase( "APPROVED" )) { if (qaStatus.equalsIgnoreCase("APPROVED")) {
// check finished item is already created // check finished item is already created
FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem( stitchingOfflineItem.getId( )); FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem(stitchingOfflineItem.getId());
if ( preCreatedItem == null) { if (preCreatedItem == null) {
FinishedItem finishedItem = new FinishedItem( ); FinishedItem finishedItem = new FinishedItem();
finishedItem.setItemId( stitchingOfflineItem.getItemId( )); finishedItem.setItemId(stitchingOfflineItem.getItemId());
finishedItem.setSku( stitchingOfflineItem.getSku( )); finishedItem.setSku(stitchingOfflineItem.getSku());
finishedItem.setBarcode( stitchingOfflineItem.getBarcode( )); finishedItem.setBarcode(stitchingOfflineItem.getBarcode());
finishedItem.setCreatedBy( authentication.getName( )); finishedItem.setCreatedBy(authentication.getName());
finishedItem.setCreatedAt( LocalDateTime.now( )); finishedItem.setCreatedAt(LocalDateTime.now());
finishedItem.setStitchedItemId( stitchingOfflineItem.getId( )); finishedItem.setStitchedItemId(stitchingOfflineItem.getId());
finishedItem.setJobCardId( stitchingOfflineItem.getJobCardId( )); finishedItem.setJobCardId(stitchingOfflineItem.getJobCardId());
finishedItem.setIsQa( false); finishedItem.setIsQa(true);
finishedItem.setId( finishedItemDAO.save( finishedItem)); finishedItem.setId(finishedItemDAO.save(finishedItem));
finishedItems.add( finishedItem); finishedItems.add(finishedItem);
InventoryTransactionLeg lastInvTransaction = lastStitchedIdInTransactionMap.getOrDefault( stitchingOfflineItem.getId( ), null); InventoryTransactionLeg lastInvTransaction = lastStitchedIdInTransactionMap.getOrDefault(stitchingOfflineItem.getId(), null);
if ( lastInvTransaction != null ) { if (lastInvTransaction != null) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId( ); long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg( transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); createInventoryTransactionLeg(transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCHING_OFFLINE.name());
} }
// update stitched item // update stitched item
stitchingOfflineItem.setIsQa( true); stitchingOfflineItem.setIsQa(true);
stitchingOfflineItem.setQaStatus(qaStatus);
updatedStitchedItems.add(stitchingOfflineItem);
// if FI is already created // if FI is already created
} else { } else {
// create OUT from stitching account Finished Item // create OUT from stitching account Finished Item
InventoryTransactionLeg lastInvTransaction = lastFinishedItemInTransactionMap.getOrDefault( preCreatedItem.getId( ), null); InventoryTransactionLeg lastInvTransaction = lastFinishedItemInTransactionMap.getOrDefault(preCreatedItem.getId(), null);
if ( lastInvTransaction != null ) { if (lastInvTransaction != null) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId( ); long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg( transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); 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 // 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 // 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 // save updated stitched items
stitchingOfflineItemDAO.saveAll( wrapper.getItems( )); finishedItemDAO.saveAll(finishedItemsForUlter);
stitchingOfflineItemDAO.saveAll(updatedStitchedItems);
} }
} }
@ -545,139 +558,163 @@ public class InventoryService {
/* /*
* segregate finish items * segregate finish items
* */ * */
@Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
public void segregateFinishedItems( FinishedItemWrapper wrapper) { public void segregateFinishedItems(FinishedItemWrapper wrapper, String status) {
if ( wrapper != null && wrapper.getItems( ) != null) { if (wrapper != null && wrapper.getItems() != null) {
List<FinishedItem> items = wrapper.getItems( ); List<FinishedItem> items = wrapper.getItems();
List<FinishedItem> updatedItems = new ArrayList<>( ); List<FinishedItem> updatedItems = new ArrayList<>();
// finished ids // finished ids
List<Long> finishedItemIds = items.stream( ).map( FinishedItem::getId) List<Long> finishedItemIds = items.stream().map(FinishedItem::getId)
.collect( Collectors.toList( )); .collect(Collectors.toList());
// stitched ids // stitched ids
List<Long> stitchedItemIds = items.stream( ).map( FinishedItem::getStitchedItemId) List<Long> stitchedItemIds = items.stream().map(FinishedItem::getStitchedItemId)
.collect( Collectors.toList( )); .collect(Collectors.toList());
// create parent doc type last IN transaction map // create parent doc type last IN transaction map
Map<Long, InventoryTransactionLeg> lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
// create parent doc type last OUT transaction map // create parent doc type last OUT transaction map
Map<Long, InventoryTransactionLeg> lastStitchedItemOutTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastStitchedItemOutTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.OUT.name( ), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.OUT.name(), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
// create transaction // 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 // create IN and OUT for all approved items
for ( FinishedItem finishedItem : items) { for (FinishedItem finishedItem : items) {
InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault(finishedItem.getId(), null);
finishedItem.setIsQa( true); finishedItem.setIsQa(true);
/*
* item is not approved and washed is selected then item remain in Finishing account
* */
/* /*
* item is approved and alter is selected then finished item will to stitching account * 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 // create OUT and IN transactions for FI
if ( lastInvTransaction != null) { if (lastInvTransaction != null) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId( ); long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name());
// IN // IN
// get the stitching account id // get the stitching account id
long stitchedItemId = finishedItem.getStitchedItemId( ); long stitchedItemId = finishedItem.getStitchedItemId();
InventoryTransactionLeg lastOutTransaction = lastStitchedItemOutTransactionMap.getOrDefault( stitchedItemId, null); InventoryTransactionLeg lastOutTransaction = lastStitchedItemOutTransactionMap.getOrDefault(stitchedItemId, null);
createInventoryTransactionLeg( transaction, finishedItem, lastOutTransaction.getAccountId( ), InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); createInventoryTransactionLeg(transaction, finishedItem, lastOutTransaction.getAccountId(), InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.STITCHING_OFFLINE.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 * item is approved and grade is selected then fI is move to grade account
*/ */
if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "APPROVED") && finishedItem.getAccountId( ) != 0) { if (status.equalsIgnoreCase("APPROVED")) {
finishedItem.setIsSegregated( true); finishedItem.setQaStatus("APPROVED");
finishedItem.setIsSegregated(true);
} }
updatedItems.add( finishedItem); updatedItems.add(finishedItem);
} }
// save finish items // save finish items
finishedItemDAO.saveAll( updatedItems); finishedItemDAO.saveAll(updatedItems);
} }
} }
/* /*
* Packaging items * Packaging items
* */ * */
@Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) @Transactional(rollbackFor = Exception.class, propagation = Propagation.NESTED)
public void createPackagingItemAndTransaction( FinishedItemWrapper wrapper) { public void createPackagingItemAndTransaction(FinishedItemWrapper wrapper) {
if ( wrapper != null && wrapper.getItems( ) != null) { if (wrapper != null && wrapper.getItems() != null) {
List<FinishedItem> items = wrapper.getItems( ); List<FinishedItem> items = wrapper.getItems();
List<FinishedItem> updatedItems = new ArrayList<>( ); List<FinishedItem> updatedItems = new ArrayList<>();
List<PackagingItems> packagingItems = new ArrayList<>( ); List<PackagingItems> packagingItems = new ArrayList<>();
// finished ids // finished ids
List<Long> finishedItemIds = items.stream( ).map( FinishedItem::getId) List<Long> finishedItemIds = items.stream().map(FinishedItem::getId)
.collect( Collectors.toList( )); .collect(Collectors.toList());
// stitched ids // stitched ids
List<Long> stitchedItemIds = items.stream( ).map( FinishedItem::getStitchedItemId) List<Long> stitchedItemIds = items.stream().map(FinishedItem::getStitchedItemId)
.collect( Collectors.toList( )); .collect(Collectors.toList());
// find parent doc type last IN transaction map // find parent doc type last IN transaction map
Map<Long, InventoryTransactionLeg> lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO Map<Long, InventoryTransactionLeg> lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO
.findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name())
.stream( ) .stream()
.collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity()));
// create transaction // 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 // create IN and OUT for all approved items
for ( FinishedItem finishedItem : items) { for (FinishedItem finishedItem : items) {
InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault(finishedItem.getId(), null);
finishedItem.setIsQa( true); finishedItem.setIsQa(true);
if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "APPROVED") && finishedItem.getIsSegregated( )) { if (finishedItem.getQaStatus().equalsIgnoreCase("APPROVED") && finishedItem.getIsSegregated()) {
// create OUT and IN transactions for FI // create OUT and IN transactions for FI
PackagingItems packagingItems1 = (createPackagingItem(finishedItem)); PackagingItems packagingItems1 = (createPackagingItem(finishedItem));
packagingItems1.setId(packagingItemsDAO.save(packagingItems1)); packagingItems1.setId(packagingItemsDAO.save(packagingItems1));
if ( lastInvTransaction != null) { if (lastInvTransaction != null) {
// OUT // OUT
long fromAccount = lastInvTransaction.getAccountId( ); long fromAccount = lastInvTransaction.getAccountId();
createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name());
// IN // 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.setIsSegregated(true);
finishedItem.setPackaging( true); finishedItem.setPackaging(true);
packagingItems.add(packagingItems1); packagingItems.add(packagingItems1);
} }
updatedItems.add( finishedItem); updatedItems.add(finishedItem);
} }
// save finish items // save finish items
finishedItemDAO.saveAll( updatedItems); finishedItemDAO.saveAll(updatedItems);
packagingItemsDAO.saveAll(packagingItems); packagingItemsDAO.saveAll(packagingItems);
} }
} }
/* /*
* find item summary by account * find item summary by account
* */ * */
public List<InventorySummary> findItemSummaryByAccountId( long accountId) { public List<InventorySummary> findItemSummaryByAccountId(long accountId) {
return inventoryTransactionLegDAO.findSummaryByAccountId( accountId); return inventoryTransactionLegDAO.findSummaryByAccountId(accountId);
} }
private PackagingItems createPackagingItem(FinishedItem finishedItem){ private PackagingItems createPackagingItem(FinishedItem finishedItem) {
Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
PackagingItems packagingItems = new PackagingItems(); PackagingItems packagingItems = new PackagingItems();
packagingItems.setItemId(finishedItem.getItemId()); packagingItems.setItemId(finishedItem.getItemId());
packagingItems.setAccountId(finishedItem.getAccountId()); packagingItems.setAccountId(finishedItem.getAccountId());
@ -687,7 +724,7 @@ public class InventoryService {
packagingItems.setSku(finishedItem.getSku()); packagingItems.setSku(finishedItem.getSku());
packagingItems.setBarcode(finishedItem.getBarcode()); packagingItems.setBarcode(finishedItem.getBarcode());
packagingItems.setCreatedAt(LocalDateTime.now()); packagingItems.setCreatedAt(LocalDateTime.now());
packagingItems.setCreatedBy(authentication.getName( )); packagingItems.setCreatedBy(authentication.getName());
packagingItems.setIsQa(finishedItem.getIsQa()); packagingItems.setIsQa(finishedItem.getIsQa());
packagingItems.setIsSegregated(finishedItem.getIsSegregated()); packagingItems.setIsSegregated(finishedItem.getIsSegregated());
packagingItems.setQaStatus(finishedItem.getQaStatus()); packagingItems.setQaStatus(finishedItem.getQaStatus());

View File

@ -213,31 +213,27 @@ public class ReportingService {
return new HashMap<>(); return new HashMap<>();
}else { }else {
HashMap<String,Integer> gradingItems = new HashMap<>(); HashMap<String,Integer> gradingItems = new HashMap<>();
List<InventoryAccount> inventoryAccounts = inventoryAccountDAO.getPackagingAccounts();
List<FinishedItem> finishedItems = finishedItemDAO.findByJobCardId(Long.parseLong(jobCardID)); List<FinishedItem> finishedItems = finishedItemDAO.findByJobCardId(Long.parseLong(jobCardID));
List<PackagingItems> packagingItems = packagingItemsDAO.findByJobCardId(Long.parseLong(jobCardID));
List<Long> finishItemsIds = finishedItems.stream() List<FinishedItem> bGradeFinishItemsIds= finishedItems.stream()
.map(FinishedItem::getId).collect(Collectors.toList()); .filter(item -> "B GRADE".equals(item.getQaStatus())).collect(Collectors.toList());
List<Long> packagingItemsIds = packagingItems.stream() List<FinishedItem> cGradeFinishItemsIds= finishedItems.stream()
.map(PackagingItems::getId).collect(Collectors.toList()); .filter(item -> "C GRADE".equals(item.getQaStatus())).collect(Collectors.toList());
if (finishItemsIds.isEmpty()){ List<FinishedItem> aGradeFinishItemsIds= finishedItems.stream()
.filter(item -> "APPROVED".equals(item.getQaStatus())).collect(Collectors.toList());
if (finishedItems.isEmpty()){
gradingItems.put("A GRADE",0); gradingItems.put("A GRADE",0);
gradingItems.put("B GRADE",0); gradingItems.put("B GRADE",0);
gradingItems.put("C GRADE",0); gradingItems.put("C GRADE",0);
return gradingItems; return gradingItems;
}else { }else {
for (InventoryAccount inventoryAccount : inventoryAccounts){ gradingItems.put("B GRADE",bGradeFinishItemsIds.size());
if (inventoryAccount.getIsPackaging()){ gradingItems.put("C GRADE",cGradeFinishItemsIds.size());
long totalGradingItems = inventoryTransactionLegDAO.CalculateTotalGradingItems(packagingItemsIds,(int) inventoryAccount.getId()); gradingItems.put("A GRADE",aGradeFinishItemsIds.size());
gradingItems.put(inventoryAccount.getTitle(), (int) totalGradingItems);
}else {
long totalGradingItems = inventoryTransactionLegDAO.CalculateTotalGradingItems(finishItemsIds,(int) inventoryAccount.getId());
gradingItems.put(inventoryAccount.getTitle(), (int) totalGradingItems);
}
}
return gradingItems; return gradingItems;
} }
} }
@ -386,11 +382,6 @@ public class ReportingService {
} }
List<InventoryAccount> inventoryAccounts = inventoryAccountDAO.findByParentEntityTypeAndParentId("PROCESS",6L); List<InventoryAccount> inventoryAccounts = inventoryAccountDAO.findByParentEntityTypeAndParentId("PROCESS",6L);
List<JobCardItem> jobCardItems = jobCardItemDAO.findByCardId(Long.parseLong(jobCardID));
BigDecimal actualProduction = jobCardItems.stream()
.map(item -> Optional.ofNullable(item.getActualProduction()).orElse(BigDecimal.ZERO))
.reduce(BigDecimal.ZERO, BigDecimal::add);
LocalDateTime startDate = jobCardDAO.find(Long.parseLong(jobCardID)).getCreatedAt(); LocalDateTime startDate = jobCardDAO.find(Long.parseLong(jobCardID)).getCreatedAt();
HashMap<String, List<?>> barChartData = new HashMap<>(); HashMap<String, List<?>> barChartData = new HashMap<>();
@ -437,15 +428,9 @@ public class ReportingService {
stitchingList.set(index, stitchingList.get(index) + leg.getQuantity().intValue()); stitchingList.set(index, stitchingList.get(index) + leg.getQuantity().intValue());
} }
else if ("FINISHED_ITEM".equals(leg.getParentDocumentType()) && (leg.getAccountId().equals(7) || leg.getAccountId().equals(12))) { else if ("FINISHED_ITEM".equals(leg.getParentDocumentType()) && (leg.getAccountId().equals(7) || leg.getAccountId().equals(12))) {
if (index == 0 || !dateIndexMap.containsKey(dateKey)) {
qualityList.set(index, 0);
}
qualityList.set(index, qualityList.get(index) + leg.getQuantity().intValue()); qualityList.set(index, qualityList.get(index) + leg.getQuantity().intValue());
} }
else if ("PACKAGING".equals(leg.getParentDocumentType()) && inventoryAccounts.stream().anyMatch(e -> e.getId() == leg.getAccountId().longValue())) { else if ("PACKAGING".equals(leg.getParentDocumentType()) && inventoryAccounts.stream().anyMatch(e -> e.getId() == leg.getAccountId().longValue())) {
if (index == 0 || !dateIndexMap.containsKey(dateKey)) {
finishItems.set(index, 0);
}
finishItems.set(index, finishItems.get(index) + leg.getQuantity().intValue()); finishItems.set(index, finishItems.get(index) + leg.getQuantity().intValue());
} }
} }

View File

@ -1,9 +1,8 @@
( async function(){ (async function () {
Vue.prototype.$accounts = window.ctp.accounts; Vue.prototype.$accounts = window.ctp.accounts;
Vue.component('finished-item-table',{ Vue.component('finished-item-table', {
props : [ 'items' ], props: ['items'],
methods: { methods: {
getFormattedDateTime: function (dateTime) { getFormattedDateTime: function (dateTime) {
if (!!dateTime) { if (!!dateTime) {
@ -15,8 +14,8 @@
this.$emit('remove-item', index) this.$emit('remove-item', index)
} }
}, },
template : ` template: `
<table class="table table-bordered bg-white col-sm-12"> <table class="table table-bordered bg-white col-sm-12">
<thead> <thead>
<tr> <tr>
<th>ID</th> <th>ID</th>
@ -27,68 +26,53 @@
<th>Job Card ID</th> <th>Job Card ID</th>
<th>Barcode</th> <th>Barcode</th>
<th>Status</th> <th>Status</th>
<th>Account</th>
<th>Action</th> <th>Action</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<tr v-for="(item,index) in items"> <tr v-for="(item,index) in items">
<td> <td>
<input hidden="hidden" v-bind:name="'items[' + index + '].id'" v-bind:value="item.id"> <input type="hidden" v-bind:name="'items[' + index + '].id'" v-bind:value="item.id">
<input hidden="hidden" v-bind:name="'items[' + index + '].itemId'" v-bind:value="item.itemId"> <input type="hidden" v-bind:name="'items[' + index + '].itemId'" v-bind:value="item.itemId">
<input hidden="hidden" v-bind:name="'items[' + index + '].sku'" v-bind:value="item.sku"> <input type="hidden" v-bind:name="'items[' + index + '].sku'" v-bind:value="item.sku">
<input hidden="hidden" v-bind:name="'items[' + index + '].createdBy'" v-bind:value="item.createdBy"> <input type="hidden" v-bind:name="'items[' + index + '].createdBy'" v-bind:value="item.createdBy">
<input hidden="hidden" v-bind:name="'items[' + index + '].createdAt'" v-bind:value="getFormattedDateTime(item.createdAt)"> <input type="hidden" v-bind:name="'items[' + index + '].createdAt'" v-bind:value="getFormattedDateTime(item.createdAt)">
<input hidden="hidden" v-bind:name="'items[' + index + '].jobCardId'" v-bind:value="item.jobCardId"> <input type="hidden" v-bind:name="'items[' + index + '].jobCardId'" v-bind:value="item.jobCardId">
<input hidden="hidden" v-bind:name="'items[' + index + '].barcode'" v-bind:value="item.barcode" > <input type="hidden" v-bind:name="'items[' + index + '].barcode'" v-bind:value="item.barcode">
<input hidden="hidden" v-bind:name="'items[' + index + '].isQa'" v-bind:value="item.isQa"> <input type="hidden" v-bind:name="'items[' + index + '].isQa'" v-bind:value="item.isQa">
<input hidden="hidden" v-bind:name="'items[' + index + '].stitchedItemId'" v-bind:value="item.stitchedItemId"> <input type="hidden" v-bind:name="'items[' + index + '].stitchedItemId'" v-bind:value="item.stitchedItemId">
<input hidden="hidden" v-bind:name="'items[' + index + '].isSegregated'" v-bind:value="item.isSegregated"> <input type="hidden" v-bind:name="'items[' + index + '].isSegregated'" v-bind:value="item.isSegregated">
<span> {{item.id}} </span> <span> {{item.id}} </span>
</td> </td>
<td> {{item.itemId}} </td> <td> {{item.itemId}} </td>
<td> {{item.sku}} </td> <td> {{item.sku}} </td>
<td> {{item.createdBy}} </td> <td> {{item.createdBy}} </td>
<td> {{ getFormattedDateTime( item.createdAt) }} </td> <td> {{ getFormattedDateTime(item.createdAt) }} </td>
<td> {{item.jobCardId}}</td> <td> {{item.jobCardId}} </td>
<td> {{item.barcode}} </td> <td> {{item.barcode}} </td>
<td> <td>
<select class="w-100" required v-bind:name="'items[' + index + '].qaStatus'" v-model="item.qaStatus"> <span v-if="!item.qaStatus" class="badge badge-danger">NOT PERFORMED</span>
<option value="WASHED">WASHED</option> <span v-else-if="item.qaStatus === 'APPROVED'" class="font-lg badge badge-success">{{ item.qaStatus }}</span>
<option value="ALTER">ALTER</option> <span v-else-if="item.qaStatus === 'ALTER' || item.qaStatus === 'B GRADE' || item.qaStatus === 'C GRADE' " class="font-lg badge badge-danger">{{ item.qaStatus }}</span>
<option value="APPROVED">APPROVED</option> <span v-else-if="item.qaStatus === 'WASHED'" class="font-lg badge badge-APPROVED">{{ item.qaStatus }}</span>
</select><br>
<!-- <textarea class="w-100 mt-1" rows="2" v-model="item.qaRemarks" -->
<!-- v-if="item.accountId === '0'" -->
<!-- v-bind:name="'items[' + index + '].qaRemarks'"></textarea> -->
</td>
<td> <td>
<select class="w-100" required v-bind:name="'items[' + index + '].accountId'" <button type="button" class="btn btn-light" v-on:click="removeItem(index)">
v-model="item.accountId"
v-bind:disabled="item.qaStatus !== 'APPROVED'"
v-bind:required="item.qaStatus === 'APPROVED'">
<option v-for="(option,index) in $accounts"
v-bind:value="option.id">{{option.title}}</option>
</select>
</td>
<td>
<button type="button" title="Remove" class="btn btn-light text-left" v-on:click="removeItem(index)">
<i class="bi bi-trash"></i> <i class="bi bi-trash"></i>
</button> </button>
</td> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>
`, `
});
})
let app = new Vue({ let app = new Vue({
el : '#finishedApp', el: '#finishedApp',
data : { data: {
items : [] items: [],
QaStatus: 'APPROVED'
}, },
methods : { methods: {
onItemSelect: function (id, item) { onItemSelect: function (id, item) {
this.items.push(item); this.items.push(item);
}, },
@ -100,10 +84,15 @@
const uniqueIds = new Set(ids); const uniqueIds = new Set(ids);
return ids.length !== uniqueIds.size; return ids.length !== uniqueIds.size;
}, },
submitWithQaStatus: function (status) {
this.QaStatus = status;
this.$nextTick(() => {
document.getElementById('finishedApp').submit();
});
}
}, },
mounted : function () { mounted: function () {
console.log( this.$accounts ) console.log(this.$accounts);
} }
}) });
})(jQuery);
})(jQuery)

View File

@ -53,7 +53,13 @@
<td> {{ getFormattedDateTime( item.createdAt) }} </td> <td> {{ getFormattedDateTime( item.createdAt) }} </td>
<td> {{item.jobCardId}}</td> <td> {{item.jobCardId}}</td>
<td> {{item.barcode}} </td> <td> {{item.barcode}} </td>
<td > {{item.qaStatus}} </td> <td >
<span v-if="!item.qaStatus" class="badge badge-danger">NOT PERFORMED</span>
<span v-else-if="item.qaStatus === 'APPROVED'" class="font-lg badge badge-success">{{ item.qaStatus }}</span>
<span v-else-if="item.qaStatus === 'ALTER' || item.qaStatus === 'B GRADE'" class="font-lg badge badge-danger">{{ item.qaStatus }}</span>
<span v-else-if="item.qaStatus === 'WASHED'" class="font-lg badge badge-APPROVED">{{ item.qaStatus }}</span>
</td>
<td> <td>
<button type="button" title="Remove" class="btn btn-light text-left" v-on:click="removeItem(index)"> <button type="button" title="Remove" class="btn btn-light text-left" v-on:click="removeItem(index)">
<i class="bi bi-trash"></i> <i class="bi bi-trash"></i>

View File

@ -50,12 +50,10 @@
<td> {{item.jobCardId}}</td> <td> {{item.jobCardId}}</td>
<td> {{item.barcode}} </td> <td> {{item.barcode}} </td>
<td> <td>
<select class="w-100" required v-bind:name="'items[' + index + '].qaStatus'" v-model="item.qaStatus"> <span v-if="!item.qaStatus" class="badge badge-danger">NOT PERFORMED</span>
<option value="APPROVED">APPROVED</option> <span v-else-if="item.qaStatus === 'APPROVED'" class="font-lg badge badge-success">{{ item.qaStatus }}</span>
<option value="REJECT">REJECT</option> <span v-else-if="item.qaStatus === 'REJECT'" class="font-lg badge badge-danger">{{ item.qaStatus }}</span>
</select><br> </td>
<textarea class="w-100 mt-1" rows="2" v-model="item.remarks" v-if="item.qaStatus === 'REJECT'" v-bind:name="'items[' + index + '].qaRemarks'"></textarea>
</td>
<td> <td>
<button type="button" title="Remove" class="btn btn-light text-left" v-on:click="removeItem(index)"> <button type="button" title="Remove" class="btn btn-light text-left" v-on:click="removeItem(index)">
<i class="bi bi-trash"></i> <i class="bi bi-trash"></i>
@ -72,6 +70,7 @@
el: '#qcForm', el: '#qcForm',
data: { data: {
items: [], items: [],
QaStatus: 'APPROVED'
}, },
methods: { methods: {
onItemSelect: function (id, item) { onItemSelect: function (id, item) {
@ -86,6 +85,12 @@
const uniqueIds = new Set(ids); const uniqueIds = new Set(ids);
return ids.length !== uniqueIds.size; return ids.length !== uniqueIds.size;
}, },
submitWithQaStatus: function (status) {
this.QaStatus = status;
this.$nextTick(() => {
document.getElementById('qcForm').submit();
});
}
}, },
mounted: function () { mounted: function () {

View File

@ -1,54 +1,70 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml" <html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml"
xmlns:v-bind="http://www.w3.org/1999/xhtml"> xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head('Segregate Finished Items')"></head> <head th:replace="_fragments :: head('Segregate Finished Items')"></head>
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
<header class="row page-header" th:replace="_fragments :: page-header"></header> <header class="row page-header" th:replace="_fragments :: page-header"></header>
<main class="row page-main"> <main class="row page-main">
<div class="col-sm"> <div class="col-sm">
<div class="mb-4 d-flex justify-content-between"> <div class="mb-4 d-flex justify-content-between">
<h3>Segregate Finished Items</h3> <h3>Segregate Finished Items</h3>
</div>
<form th:action="'/ctp/finishing/segregate-inventory'" method="post" id="finishedApp">
<div class="bg-light p-3 mb-3">
<div class="form-row">
<div class="col-sm-3 form-group">
<search-item
url="/ctp/rest/finished-items/search"
v-on:finished-item-select="onItemSelect">
</search-item>
</div>
<div class="col-sm-3 form-group">
<!-- <label>Packaging Account</label>-->
<!-- <select class="form-control" name="account-id" th:field="*{finishedAccountId}" required>-->
<!-- <option value="">PLease select</option>-->
<!-- <option th:each="account : ${accounts}"-->
<!-- th:value="${account.id}"-->
<!-- th:text="${account.title}"></option>-->
<!-- </select>-->
</div>
</div> </div>
<form th:action="'/ctp/finishing/segregate-inventory'" method="post" id="finishedApp"> <input type="hidden" name="qaStatus" v-model="QaStatus">
<div class="bg-light p-3 mb-3">
<div class="form-row">
<div class="col-sm-3 form-group">
<search-item
url="/ctp/rest/finished-items/search"
v-on:finished-item-select="onItemSelect">
</search-item>
</div>
<div class="col-sm-3 form-group">
<!-- <label>Packaging Account</label>-->
<!-- <select class="form-control" name="account-id" th:field="*{finishedAccountId}" required>-->
<!-- <option value="">PLease select</option>-->
<!-- <option th:each="account : ${accounts}"-->
<!-- th:value="${account.id}"-->
<!-- th:text="${account.title}"></option>-->
<!-- </select>-->
</div>
</div>
</div>
<div class="bg-light p-3 mb-3">
<h6 class="mb-3">Finished Items</h6>
<finished-item-table
v-bind:items="items"
v-on:remove-item="removeItem"
></finished-item-table>
</div>
<div class="alert alert-danger" v-if="hasDuplicates()" >Duplicate Item Selected</div>
<button class="btn btn-primary" type="submit" v-bind:disabled="hasDuplicates()">Submit</button>
<a th:href="@{/finishing/finished-items}" class="btn btn-light">Cancel</a>
</form>
<script th:inline="javascript">
window.ctp.accounts = [[${accounts}]];
</script>
<script th:src="@{/js/vendor/compressor.min.js}"></script>
<script th:src="@{/js/finishing/finished-item-segregation-form.js}"></script>
</div> </div>
</main> <div class="bg-light p-3 mb-3">
<h6 class="mb-3">Finished Items</h6>
<finished-item-table
v-bind:items="items"
v-on:remove-item="removeItem"
></finished-item-table>
</div>
<div class="alert alert-danger" v-if="hasDuplicates()">Duplicate Item Selected</div>
<button class="btn btn-primary mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('APPROVED')">APPROVED
</button>
<button class="btn btn-danger mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('ALTER')">ALTER
</button>
<button class="btn btn-danger mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('B GRADE')">B GRADE
</button>
<button class="btn btn-danger mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('C GRADE')">C GRADE
</button>
<button class="btn btn-success mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('WASHED')">WASHED
</button>
<a th:href="@{/finishing/finished-items}" class="btn btn-light">Cancel</a>
</form>
<script th:inline="javascript">
window.ctp.accounts = [[${accounts}]];
</script>
<script th:src="@{/js/vendor/compressor.min.js}"></script>
<script th:src="@{/js/finishing/finished-item-segregation-form.js}"></script>
</div> </div>
<div th:replace="_fragments :: page-footer-scripts"></div> </main>
</body> </div>
<div th:replace="_fragments :: page-footer-scripts"></div>
</body>
</html> </html>

View File

@ -1,55 +1,61 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml" <html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.w3.org/1999/xhtml"
xmlns:v-bind="http://www.w3.org/1999/xhtml"> xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head('Home Page')"></head> <head th:replace="_fragments :: head('Home Page')"></head>
<body> <body>
<div class="container-fluid"> <div class="container-fluid">
<header class="row page-header" th:replace="_fragments :: page-header"></header> <header class="row page-header" th:replace="_fragments :: page-header"></header>
<main class="row page-main"> <main class="row page-main">
<div class="col-sm"> <div class="col-sm">
<div class="mb-4 d-flex justify-content-between"> <div class="mb-4 d-flex justify-content-between">
<h3>Add Stitched Offline Items For QC</h3> <h3>Add Stitched Offline Items For QC</h3>
</div>
<form th:action="'/ctp/quality-control/qc-finished-item'" method="post" id="qcForm"
th:object="${wrapper}">
<div class="bg-light p-3 mb-3">
<div class="form-row">
<div class="col-sm-3 form-group">
<search-item
label="Search Stitch Item"
url="/ctp/rest/stitching-offline-items/search"
v-on:finished-item-select="onItemSelect">
</search-item>
</div>
<input type="hidden" name="qaStatus" v-model="QaStatus">
<div class="col-sm-3 form-group">
<label>Finishing Account</label>
<select class="form-control" name="account-id" th:field="*{finishedAccountId}" required>
<option value="">Please select</option>
<option th:each="account : ${accounts}"
th:value="${account.id}"
th:text="${account.title}"></option>
</select>
</div>
</div> </div>
<form th:action="'/ctp/quality-control/qc-finished-item'" method="post" id="qcForm"
th:object="${wrapper}">
<div class="bg-light p-3 mb-3">
<div class="form-row">
<div class="col-sm-3 form-group">
<search-item
label="Search Stitch Item"
url="/ctp/rest/stitching-offline-items/search"
v-on:finished-item-select="onItemSelect">
</search-item>
</div>
<div class="col-sm-3 form-group">
<label>Finishing Account</label>
<select class="form-control" name="account-id" th:field="*{finishedAccountId}" required>
<option value="">Please select</option>
<option th:each="account : ${accounts}"
th:value="${account.id}"
th:text="${account.title}"></option>
</select>
</div>
</div>
</div>
<div class="bg-light p-3 mb-3">
<h6 class="mb-3">Stitched Items</h6>
<stitched-item-table
v-bind:items="items"
v-on:remove-item="removeItem">
</stitched-item-table>
</div>
<div class="alert alert-danger" v-if="hasDuplicates()">Duplicate Item Selected</div>
<button class="btn btn-primary" type="submit" v-bind:disabled="hasDuplicates()">Submit</button>
<a th:href="@{/quality-control/qc-finished-items}" class="btn btn-light">Cancel</a>
</form>
<script th:inline="javascript">
</script>
<script th:src="@{/js/vendor/compressor.min.js}"></script>
<script th:src="@{/js/qc/finished-items-qc-form.js}"></script>
</div> </div>
</main> <div class="bg-light p-3 mb-3">
<h6 class="mb-3">Stitched Items</h6>
<stitched-item-table
v-bind:items="items"
v-on:remove-item="removeItem">
</stitched-item-table>
</div>
<div class="alert alert-danger" v-if="hasDuplicates()">Duplicate Item Selected</div>
<button class="btn btn-primary mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('APPROVED')">APPROVED
</button>
<button class="btn btn-danger mr-2" type="button" :disabled="hasDuplicates() || items.length === 0"
@click="submitWithQaStatus('REJECT')">REJECT
</button>
<a th:href="@{/quality-control/qc-finished-items}" class="btn btn-light">Cancel</a>
</form>
<script th:inline="javascript">
</script>
<script th:src="@{/js/vendor/compressor.min.js}"></script>
<script th:src="@{/js/qc/finished-items-qc-form.js}"></script>
</div> </div>
<div th:replace="_fragments :: page-footer-scripts"></div> </main>
</body> </div>
<div th:replace="_fragments :: page-footer-scripts"></div>
</body>
</html> </html>