diff --git a/src/main/java/com/utopiaindustries/auth/AdminRole.java b/src/main/java/com/utopiaindustries/auth/AdminRole.java new file mode 100644 index 0000000..313dd9b --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/AdminRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_ADMIN')") +public @interface AdminRole { +} diff --git a/src/main/java/com/utopiaindustries/auth/CuttingRole.java b/src/main/java/com/utopiaindustries/auth/CuttingRole.java new file mode 100644 index 0000000..199a3f2 --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/CuttingRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_CUTTING','ROLE_ADMIN')") +public @interface CuttingRole { +} diff --git a/src/main/java/com/utopiaindustries/auth/FinishingRole.java b/src/main/java/com/utopiaindustries/auth/FinishingRole.java new file mode 100644 index 0000000..96ab8c2 --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/FinishingRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_FINISHING','ROLE_ADMIN')") +public @interface FinishingRole { +} diff --git a/src/main/java/com/utopiaindustries/auth/JobCardRole.java b/src/main/java/com/utopiaindustries/auth/JobCardRole.java new file mode 100644 index 0000000..d302b57 --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/JobCardRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_JOB_CARD','ROLE_ADMIN')") +public @interface JobCardRole { +} diff --git a/src/main/java/com/utopiaindustries/auth/PackagingRole.java b/src/main/java/com/utopiaindustries/auth/PackagingRole.java new file mode 100644 index 0000000..9a4a416 --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/PackagingRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_PACKAGING','ROLE_ADMIN')") +public @interface PackagingRole { +} diff --git a/src/main/java/com/utopiaindustries/auth/QCRole.java b/src/main/java/com/utopiaindustries/auth/QCRole.java new file mode 100644 index 0000000..cfaa4dd --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/QCRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_QUALITY_CONTROL','ROLE_ADMIN')") +public @interface QCRole { +} diff --git a/src/main/java/com/utopiaindustries/auth/StitchingRole.java b/src/main/java/com/utopiaindustries/auth/StitchingRole.java new file mode 100644 index 0000000..c533b42 --- /dev/null +++ b/src/main/java/com/utopiaindustries/auth/StitchingRole.java @@ -0,0 +1,14 @@ +package com.utopiaindustries.auth; + +import org.springframework.security.access.prepost.PreAuthorize; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Retention(RetentionPolicy.RUNTIME) +@Target({ElementType.METHOD, ElementType.TYPE}) +@PreAuthorize( "hasAnyRole('ROLE_STITCHING','ROLE_ADMIN')") +public @interface StitchingRole { +} diff --git a/src/main/java/com/utopiaindustries/controller/CuttingController.java b/src/main/java/com/utopiaindustries/controller/CuttingController.java index 646e3d7..8406714 100644 --- a/src/main/java/com/utopiaindustries/controller/CuttingController.java +++ b/src/main/java/com/utopiaindustries/controller/CuttingController.java @@ -1,6 +1,8 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.CuttingRole; import com.utopiaindustries.dao.ctp.BundleWrapper; +import com.utopiaindustries.model.ctp.JobCardWrapper; import com.utopiaindustries.service.*; import org.springframework.core.io.InputStreamResource; import org.springframework.http.ResponseEntity; @@ -12,6 +14,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import java.util.Arrays; @Controller +@CuttingRole @RequestMapping( "/cutting" ) public class CuttingController { @@ -39,8 +42,9 @@ public class CuttingController { @GetMapping( "/receive-inventory" ) public String receiveInventoryForm( Model model ){ // 1 for cutting accounts - model.addAttribute("accounts" , inventoryAccountService.findInventoryAccounts( 1L ) ); + model.addAttribute("accounts" , inventoryAccountService.getAllCuttingAccounts() ); model.addAttribute("cutPieceTypes", jobCardService.getAllPieceTypes() ); + model.addAttribute("wrapper", new JobCardWrapper() ); return "/cutting/receive-inventory"; } @@ -63,12 +67,12 @@ public class CuttingController { } @PostMapping( "/receive-inventory" ) - public String receiveInventoryToCuttingAccount( Model model, - RedirectAttributes redirectAttributes, - @RequestParam( "job-card-id" ) long jobCardId, - @RequestParam( "account-id" ) long accountId ){ + public String receiveInventoryToCuttingAccount(Model model, + RedirectAttributes redirectAttributes, + @RequestParam( "job-card-id" ) long jobCardId, + @ModelAttribute JobCardWrapper wrapper ){ try { - inventoryService.receiveJobCardInventory( jobCardId, accountId ); + inventoryService.receiveJobCardInventory( jobCardId, wrapper ); redirectAttributes.addFlashAttribute("success", "Inventory Success Received" ); } catch ( Exception ex ){ redirectAttributes.addFlashAttribute("error", ex.getMessage() ); @@ -77,18 +81,7 @@ public class CuttingController { } - @GetMapping( "/inventory-transactions" ) - public String getInventoryTransactionsByAccount( @RequestParam( value = "account-id", required = true) long accountId, - Model model ){ - model.addAttribute("transactions", inventoryService.findTransactionByAccountId( accountId )); - return "/cutting/inventory-transactions"; - } - @GetMapping( "/inventory-summary" ) - public String getInventorySummaryByAccount( @RequestParam( value = "account-id", required = true) long accountId, Model model ){ - model.addAttribute("summaries", inventoryService.findItemSummaryByAccountId( accountId )); - return "/cutting/inventory-summary"; - } @GetMapping( "/generate-master-barcode" ) public String showMasterBundleForm( Model model ){ diff --git a/src/main/java/com/utopiaindustries/controller/FinishingController.java b/src/main/java/com/utopiaindustries/controller/FinishingController.java index f8fa0e9..a68fa6d 100644 --- a/src/main/java/com/utopiaindustries/controller/FinishingController.java +++ b/src/main/java/com/utopiaindustries/controller/FinishingController.java @@ -1,5 +1,6 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.FinishingRole; import com.utopiaindustries.dao.ctp.FinishedItemDAO; import com.utopiaindustries.model.ctp.FinishedItem; import com.utopiaindustries.model.ctp.FinishedItemWrapper; @@ -15,6 +16,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import java.util.List; @Controller +@FinishingRole @RequestMapping( "/finishing" ) public class FinishingController { diff --git a/src/main/java/com/utopiaindustries/controller/InventoryAccountController.java b/src/main/java/com/utopiaindustries/controller/InventoryAccountController.java index cf06080..8c1df3d 100644 --- a/src/main/java/com/utopiaindustries/controller/InventoryAccountController.java +++ b/src/main/java/com/utopiaindustries/controller/InventoryAccountController.java @@ -1,5 +1,6 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.AdminRole; import com.utopiaindustries.model.ctp.InventoryAccount; import com.utopiaindustries.service.InventoryAccountService; import org.springframework.stereotype.Controller; @@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; @Controller +@AdminRole @RequestMapping( "/inventory-accounts" ) public class InventoryAccountController { diff --git a/src/main/java/com/utopiaindustries/controller/InventoryTransactionController.java b/src/main/java/com/utopiaindustries/controller/InventoryTransactionController.java new file mode 100644 index 0000000..bf467e2 --- /dev/null +++ b/src/main/java/com/utopiaindustries/controller/InventoryTransactionController.java @@ -0,0 +1,32 @@ +package com.utopiaindustries.controller; + +import com.utopiaindustries.service.InventoryService; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +@Controller +@RequestMapping +public class InventoryTransactionController { + + private final InventoryService inventoryService; + + public InventoryTransactionController(InventoryService inventoryService) { + this.inventoryService = inventoryService; + } + + @GetMapping( "/inventory-transactions" ) + public String getInventoryTransactionsByAccount( @RequestParam( value = "account-id", required = true) long accountId, + Model model ){ + model.addAttribute("transactions", inventoryService.findTransactionByAccountId( accountId )); + return "/cutting/inventory-transactions"; + } + + @GetMapping( "/inventory-summary" ) + public String getInventorySummaryByAccount( @RequestParam( value = "account-id", required = true) long accountId, Model model ){ + model.addAttribute("summaries", inventoryService.findItemSummaryByAccountId( accountId )); + return "/cutting/inventory-summary"; + } +} diff --git a/src/main/java/com/utopiaindustries/controller/JobCardController.java b/src/main/java/com/utopiaindustries/controller/JobCardController.java index 9de7e2b..1387d1a 100644 --- a/src/main/java/com/utopiaindustries/controller/JobCardController.java +++ b/src/main/java/com/utopiaindustries/controller/JobCardController.java @@ -1,28 +1,53 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.JobCardRole; import com.utopiaindustries.model.ctp.JobCard; +import com.utopiaindustries.service.InventoryAccountService; import com.utopiaindustries.service.JobCardService; +import com.utopiaindustries.service.LocationService; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; import org.springframework.web.servlet.mvc.support.RedirectAttributes; +import java.util.List; + @Controller +@JobCardRole @RequestMapping( "/job-cards" ) public class JobCardController { private final JobCardService jobCardService; + private final LocationService locationService; + private final InventoryAccountService inventoryAccountService; - public JobCardController(JobCardService jobCardService){ + public JobCardController(JobCardService jobCardService, LocationService locationService, InventoryAccountService inventoryAccountService){ this.jobCardService = jobCardService; + this.locationService = locationService; + this.inventoryAccountService = inventoryAccountService; } /** * get all job cards * */ @GetMapping - public String showJobCardList( Model model ){ - model.addAttribute("cards", jobCardService.getCards() ); + public String showJobCardList( @RequestParam( value = "id", required = false ) String id, + @RequestParam( value = "code", required = false ) String code, + @RequestParam( value = "status", required = false ) String status, + @RequestParam( value = "inventory-status" , required = false) String inventoryStatus, + @RequestParam( value = "customer" ,required = false ) String customer, + @RequestParam( value = "lot-number", required = false ) String lotNumber, + @RequestParam( value = "purchase-order-id", required = false ) String purchaseOrderId, + @RequestParam( value = "location-site-id", required = false ) String locationSiteId, + @RequestParam( value = "created-start-date", required = false ) String createdStartDate, + @RequestParam( value = "created-end-date", required = false ) String createdEndDate, + @RequestParam( value = "limit" , required = false) Long limit, + Model model ){ + List cards = jobCardService.getCards( id, code, status, inventoryStatus, customer, lotNumber, purchaseOrderId, locationSiteId,createdStartDate, createdEndDate, limit ); + model.addAttribute("cards", cards ); + model.addAttribute("statuses", JobCard.Status.values() ); + model.addAttribute("invStatuses", JobCard.InventoryStatus.values() ); + model.addAttribute("locations", locationService.findAll() ); return "job-card-list"; } @@ -30,14 +55,16 @@ public class JobCardController { public String showJobCardForm( Model model ){ model.addAttribute("jobCard", jobCardService.createNewJobCard() ); model.addAttribute("cutPieceTypes", jobCardService.getAllPieceTypes() ); + model.addAttribute("accounts", inventoryAccountService.getAllCuttingAccounts( ) ); return "job-card-add"; } @GetMapping( value = "/edit/{id}" ) public String showJobCardEditForm( @PathVariable("id") long id, Model model ){ - model.addAttribute("jobCard", jobCardService.findCardRecursively( id ) ); + model.addAttribute("jobCard", jobCardService.findCardRecursivelyForView( id ) ); model.addAttribute("cutPieceTypes", jobCardService.getAllPieceTypes() ); + model.addAttribute("accounts", inventoryAccountService.getAllCuttingAccounts() ); return "job-card-edit"; } diff --git a/src/main/java/com/utopiaindustries/controller/PackagingController.java b/src/main/java/com/utopiaindustries/controller/PackagingController.java index ca7e5be..5e5ed88 100644 --- a/src/main/java/com/utopiaindustries/controller/PackagingController.java +++ b/src/main/java/com/utopiaindustries/controller/PackagingController.java @@ -1,5 +1,6 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.PackagingRole; import com.utopiaindustries.service.InventoryAccountService; import com.utopiaindustries.service.LocationService; import org.springframework.stereotype.Controller; @@ -9,6 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @Controller +@PackagingRole @RequestMapping("/packaging" ) public class PackagingController { diff --git a/src/main/java/com/utopiaindustries/controller/QualityControlController.java b/src/main/java/com/utopiaindustries/controller/QualityControlController.java index 0201c3b..49d980e 100644 --- a/src/main/java/com/utopiaindustries/controller/QualityControlController.java +++ b/src/main/java/com/utopiaindustries/controller/QualityControlController.java @@ -1,5 +1,6 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.QCRole; import com.utopiaindustries.model.ctp.FinishedItem; import com.utopiaindustries.model.ctp.StitchedItemWrapper; import com.utopiaindustries.service.BundleService; @@ -14,6 +15,7 @@ import org.springframework.web.servlet.mvc.support.RedirectAttributes; import java.util.List; @Controller +@QCRole @RequestMapping( "/quality-control" ) public class QualityControlController { diff --git a/src/main/java/com/utopiaindustries/controller/StitchingController.java b/src/main/java/com/utopiaindustries/controller/StitchingController.java index 3989b39..e0128ad 100644 --- a/src/main/java/com/utopiaindustries/controller/StitchingController.java +++ b/src/main/java/com/utopiaindustries/controller/StitchingController.java @@ -1,5 +1,6 @@ package com.utopiaindustries.controller; +import com.utopiaindustries.auth.StitchingRole; import com.utopiaindustries.model.ctp.JobCard; import com.utopiaindustries.model.ctp.StitchingOfflineItem; import com.utopiaindustries.service.*; @@ -14,6 +15,7 @@ import java.util.Arrays; import java.util.List; @Controller +@StitchingRole @RequestMapping( "/stitching" ) public class StitchingController { diff --git a/src/main/java/com/utopiaindustries/controller/UserController.java b/src/main/java/com/utopiaindustries/controller/UserController.java index d0e888f..f08e9d5 100644 --- a/src/main/java/com/utopiaindustries/controller/UserController.java +++ b/src/main/java/com/utopiaindustries/controller/UserController.java @@ -33,6 +33,7 @@ public class UserController { model.addAttribute("user", userService.createEmptyUser() ); model.addAttribute("accounts", inventoryAccountService.findInventoryAccounts() ); model.addAttribute("roles", Roles.values() ); + model.addAttribute("isNew", true ); return "_user-fragment"; } diff --git a/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java index 8bc03a4..d5cb63b 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/InventoryAccountDAO.java @@ -26,6 +26,7 @@ public class InventoryAccountDAO { private final String SELECT_BY_IDS_AND_PARENT_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids) AND parent_entity_id IN (:parent_entity_ids)", TABLE_NAME ); private final String SELECT_BY_IDS_AND_PARENT_ENTITY_TYPE_AND_PARENT_ID_AND_COUNT = String.format( "SELECT * FROM %s WHERE id IN (:ids) AND parent_entity_id = :parent_entity_id AND parent_entity_type = :parent_entity_type LIMIT :limit", TABLE_NAME ); private final String SELECT_BY_IDS_PACKAGING_AND_COUNT = String.format( "SELECT * FROM %s WHERE id IN (:ids) AND is_packaging = :is_packaging LIMIT :limit", TABLE_NAME ); + private final String SELECT_BY_PARENT_TYPE_AND_PARENT_ID = String.format( "SELECT * FROM %s WHERE parent_entity_type = :parent_entity_type AND parent_entity_id = :parent_entity_id" , TABLE_NAME ); public InventoryAccountDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; @@ -136,4 +137,11 @@ public class InventoryAccountDAO { public List findByQuery( String query ){ return namedParameterJdbcTemplate.query( query, new InventoryAccountRowMapper() ); } + + public List findByParentEntityTypeAndParentId( String parentEntityType, Long parentEntityId ){ + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("parent_entity_type" , parentEntityType ); + params.addValue("parent_entity_id", parentEntityId ); + return namedParameterJdbcTemplate.query( SELECT_BY_PARENT_TYPE_AND_PARENT_ID, params, new InventoryAccountRowMapper() ); + } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java index 0b442d9..72aeaf0 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardDAO.java @@ -25,6 +25,7 @@ public class JobCardDAO { private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, code, job_order_id, created_at, created_by, status, inventory_status, customer, lot_number, purchase_order_id, location_site_id, description) VALUES (:id, :code, :job_order_id, :created_at, :created_by, :status, :inventory_status, :customer, :lot_number, :purchase_order_id, :location_site_id, :description) ON DUPLICATE KEY UPDATE code = VALUES(code), job_order_id = VALUES(job_order_id), created_at = VALUES(created_at), created_by = VALUES(created_by), status = VALUES(status), inventory_status = VALUES(inventory_status), customer = VALUES(customer), lot_number = VALUES(lot_number), purchase_order_id = VALUES(purchase_order_id), location_site_id = VALUES(location_site_id), description = VALUES(description)", TABLE_NAME ); private final String SELECT_BY_LIKE_CODE_AND_INV_STATUS_AND_STATUS = String.format( "SELECT * FROM %s WHERE code like :code AND status = :status AND inventory_status = :inventory_status", TABLE_NAME ); private final String SELECT_BY_LIKE_CODE = String.format( "SELECT * FROM %s WHERE code like :code", TABLE_NAME ); + private final String SELECT_BY_LIMIT = String.format( "SELECT * FROM %s WHERE created_by = :created_by ORDER BY id DESC limit :limit", TABLE_NAME ); // prepare query params @@ -98,4 +99,15 @@ public class JobCardDAO { params.addValue("status", status ); return namedParameterJdbcTemplate.query(SELECT_BY_LIKE_CODE_AND_INV_STATUS_AND_STATUS, params, new JobCardRowMapper() ); } + + public List findByUserAndLimit( String createdBy, Long limit ){ + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue("limit", limit.intValue() ); + params.addValue("created_by", createdBy ); + return namedParameterJdbcTemplate.query( SELECT_BY_LIMIT, params, new JobCardRowMapper() ); + } + + public List findByQuery( String query ){ + return namedParameterJdbcTemplate.query( query, new JobCardRowMapper() ); + } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java index 96c1c6c..8cf2b09 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemDAO.java @@ -10,6 +10,7 @@ import org.springframework.stereotype.Repository; import java.util.ArrayList; import java.util.List; +import java.util.Map; @Repository public class JobCardItemDAO { @@ -21,7 +22,9 @@ public class JobCardItemDAO { private final String SELECT_ALL_QUERY = String.format( "SELECT * FROM %s ORDER BY id DESC", TABLE_NAME ); private final String DELETE_QUERY = String.format( "DELETE FROM %s WHERE id = :id", TABLE_NAME ); private final String SELECT_BY_CARD_ID = String.format( "SELECT * FROM %s WHERE job_card_id = :card_id", TABLE_NAME ); - private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, job_card_id, item_id, sku, expected_production_quantity, total_production) VALUES (:id, :job_card_id, :item_id, :sku, :expected_production_quantity, :total_production) ON DUPLICATE KEY UPDATE job_card_id = VALUES(job_card_id), item_id = VALUES(item_id), sku = VALUES(sku), expected_production_quantity = VALUES(expected_production_quantity), total_production = VALUES(total_production)", TABLE_NAME ); + private final String INSERT_QUERY = String.format( "INSERT INTO %s (id, job_card_id, item_id, sku, expected_production, actual_production, total_production, account_id, length, width, gsm, wt_ply, ply) VALUES (:id, :job_card_id, :item_id, :sku, :expected_production, :actual_production, :total_production, :account_id, :length, :width, :gsm, :wt_ply, :ply) ON DUPLICATE KEY UPDATE job_card_id = VALUES(job_card_id), item_id = VALUES(item_id), sku = VALUES(sku), expected_production = VALUES(expected_production), actual_production = VALUES(actual_production), total_production = VALUES(total_production), account_id = VALUES(account_id), length = VALUES(length), width = VALUES(width), gsm = VALUES(gsm), wt_ply = VALUES(wt_ply), ply = VALUES(ply) ", TABLE_NAME ); + private final String SELECT_BY_IDS = String.format( "SELECT * FROM %s WHERE id IN (:ids)", TABLE_NAME ); + private final String SELECT_BY_JOB_CARD_AND_ACCOUNT_IDS = String.format( "SELECT * FROM %s WHERE job_card_id = :job_card_id AND actual_production = :actual_production AND account_id IN (:account_ids)", TABLE_NAME ); public JobCardItemDAO(NamedParameterJdbcTemplate namedParameterJdbcTemplate) { this.namedParameterJdbcTemplate = namedParameterJdbcTemplate; @@ -34,8 +37,15 @@ public class JobCardItemDAO { .addValue( "job_card_id", jobCardItem.getJobCardId() ) .addValue( "item_id", jobCardItem.getItemId() ) .addValue( "sku", jobCardItem.getSku() ) - .addValue( "expected_production_quantity", jobCardItem.getExpectedProductionQuantity() ) - .addValue("total_production", jobCardItem.getTotalProduction() ); + .addValue( "expected_production", jobCardItem.getExpectedProduction() ) + .addValue("actual_production", jobCardItem.getActualProduction() ) + .addValue("total_production", jobCardItem.getTotalProduction() ) + .addValue("account_id", jobCardItem.getAccountId() ) + .addValue("length", jobCardItem.getLength() ) + .addValue("width", jobCardItem.getWidth() ) + .addValue("gsm", jobCardItem.getGsm() ) + .addValue("wt_ply", jobCardItem.getWtPly() ) + .addValue("ply", jobCardItem.getPly() ); return params; } @@ -84,4 +94,19 @@ public class JobCardItemDAO { params.addValue( "card_id", cardId ); return namedParameterJdbcTemplate.query(SELECT_BY_CARD_ID, params, new JobCardItemRowMapper() ); } + + public List findByIds( List ids ){ + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue( "ids", ids ); + return namedParameterJdbcTemplate.query( SELECT_BY_IDS, params, new JobCardItemRowMapper() ); + } + + public List findByJobCardAndAccountIdsAndIsReceived( Long jobCardId, Long actualProduction, List accountIds ){ + if( accountIds == null || accountIds.isEmpty() ) return new ArrayList<>(); + MapSqlParameterSource params = new MapSqlParameterSource(); + params.addValue( "account_ids", accountIds ); + params.addValue("job_card_id", jobCardId ); + params.addValue("actual_production", actualProduction ); + return namedParameterJdbcTemplate.query( SELECT_BY_JOB_CARD_AND_ACCOUNT_IDS , params, new JobCardItemRowMapper() ); + } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java index 07ec236..e3f58c3 100644 --- a/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java +++ b/src/main/java/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.java @@ -13,8 +13,15 @@ public class JobCardItemRowMapper implements RowMapper { jobCardItem.setJobCardId( rs.getLong( "job_card_id" ) ); jobCardItem.setItemId( rs.getLong( "item_id" ) ); jobCardItem.setSku( rs.getString( "sku" ) ); - jobCardItem.setExpectedProductionQuantity( rs.getBigDecimal( "expected_production_quantity" ) ); + jobCardItem.setExpectedProduction( rs.getBigDecimal( "expected_production" ) ); + jobCardItem.setActualProduction( rs.getBigDecimal("actual_production" ) ); jobCardItem.setTotalProduction( rs.getBigDecimal("total_production" ) ); + jobCardItem.setAccountId( rs.getLong("account_id" ) ); + jobCardItem.setLength( rs.getString("length" ) ); + jobCardItem.setWidth( rs.getString("width") ) ; + jobCardItem.setGsm( rs.getString("gsm" ) ); + jobCardItem.setWtPly( rs.getString("wt_ply" ) ); + jobCardItem.setPly( rs.getString("ply" ) ); return jobCardItem; } } \ No newline at end of file diff --git a/src/main/java/com/utopiaindustries/model/Roles.java b/src/main/java/com/utopiaindustries/model/Roles.java index f5d44fd..e7c3e3c 100644 --- a/src/main/java/com/utopiaindustries/model/Roles.java +++ b/src/main/java/com/utopiaindustries/model/Roles.java @@ -3,8 +3,10 @@ package com.utopiaindustries.model; public enum Roles { ROLE_ADMIN, ROLE_USER, + ROLE_JOB_CARD, ROLE_CUTTING, ROLE_STITCHING, ROLE_QUALITY_CONTROL, + ROLE_FINISHING, ROLE_PACKAGING } diff --git a/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java b/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java index 881031e..23d9585 100644 --- a/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java +++ b/src/main/java/com/utopiaindustries/model/ctp/JobCardItem.java @@ -9,15 +9,24 @@ public class JobCardItem { private long jobCardId; private long itemId; private String sku; - private BigDecimal expectedProductionQuantity; + private BigDecimal expectedProduction; + private BigDecimal actualProduction; private BigDecimal totalProduction; + private long accountId; private BigDecimal production; + private String length; + private String width; + private String gsm; + private String wtPly; + private String ply; // wrapper private List cutPieces; private String title; + private boolean isSelected; public JobCardItem() { - this.expectedProductionQuantity = BigDecimal.ZERO; + this.expectedProduction = BigDecimal.ZERO; + this.actualProduction = BigDecimal.ZERO; this.totalProduction = BigDecimal.ZERO; this.production = BigDecimal.ZERO; } @@ -54,12 +63,20 @@ public class JobCardItem { this.sku = sku; } - public BigDecimal getExpectedProductionQuantity() { - return expectedProductionQuantity; + public BigDecimal getExpectedProduction() { + return expectedProduction; } - public void setExpectedProductionQuantity(BigDecimal expectedProductionQuantity) { - this.expectedProductionQuantity = expectedProductionQuantity; + public void setExpectedProduction(BigDecimal expectedProduction) { + this.expectedProduction = expectedProduction; + } + + public BigDecimal getActualProduction() { + return actualProduction; + } + + public void setActualProduction(BigDecimal actualProduction) { + this.actualProduction = actualProduction; } public List getCutPieces() { @@ -86,6 +103,14 @@ public class JobCardItem { this.totalProduction = totalProduction; } + public long getAccountId() { + return accountId; + } + + public void setAccountId(long accountId) { + this.accountId = accountId; + } + public BigDecimal getProduction() { return production; } @@ -94,6 +119,54 @@ public class JobCardItem { this.production = production; } + public String getLength() { + return length; + } + + public void setLength(String length) { + this.length = length; + } + + public String getWidth() { + return width; + } + + public void setWidth(String width) { + this.width = width; + } + + public String getGsm() { + return gsm; + } + + public void setGsm(String gsm) { + this.gsm = gsm; + } + + public String getWtPly() { + return wtPly; + } + + public void setWtPly(String wtPly) { + this.wtPly = wtPly; + } + + public String getPly() { + return ply; + } + + public void setPly(String ply) { + this.ply = ply; + } + + public boolean getIsSelected() { + return isSelected; + } + + public void setIsSelected(boolean selected) { + isSelected = selected; + } + @Override public boolean equals(Object o) { if (this == o) return true; @@ -114,7 +187,15 @@ public class JobCardItem { ", jobCardId=" + jobCardId + ", itemId=" + itemId + ", sku='" + sku + '\'' + - ", expectedProductionQuantity=" + expectedProductionQuantity + + ", expectedProduction=" + expectedProduction + + ", actualProduction=" + actualProduction + + ", totalProduction=" + totalProduction + + ", production=" + production + + ", length='" + length + '\'' + + ", width='" + width + '\'' + + ", gsm='" + gsm + '\'' + + ", wtPly='" + wtPly + '\'' + + ", ply='" + ply + '\'' + ", cutPieces=" + cutPieces + ", title='" + title + '\'' + '}'; diff --git a/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java new file mode 100644 index 0000000..af83ec6 --- /dev/null +++ b/src/main/java/com/utopiaindustries/model/ctp/JobCardItemWrapper.java @@ -0,0 +1,54 @@ +package com.utopiaindustries.model.ctp; + +import java.math.BigDecimal; +import java.util.List; + +public class JobCardItemWrapper { + + private long jobCardId; + private long jobCardItemId; + private List pieces; + private BigDecimal actualProduction; + + public long getJobCardId() { + return jobCardId; + } + + public void setJobCardId(long jobCardId) { + this.jobCardId = jobCardId; + } + + public long getJobCardItemId() { + return jobCardItemId; + } + + public void setJobCardItemId(long jobCardItemId) { + this.jobCardItemId = jobCardItemId; + } + + public List getPieces() { + return pieces; + } + + public void setPieces(List pieces) { + this.pieces = pieces; + } + + public BigDecimal getActualProduction() { + return actualProduction; + } + + public void setActualProduction(BigDecimal actualProduction) { + this.actualProduction = actualProduction; + } + + @Override + public String toString() { + return "JobCardItemWrapper{" + + "jobCardId=" + jobCardId + + ", jobCardItemId=" + jobCardItemId + + ", pieces=" + pieces + + ", actualProduction=" + actualProduction + + '}'; + } +} diff --git a/src/main/java/com/utopiaindustries/model/ctp/JobCardWrapper.java b/src/main/java/com/utopiaindustries/model/ctp/JobCardWrapper.java new file mode 100644 index 0000000..3376018 --- /dev/null +++ b/src/main/java/com/utopiaindustries/model/ctp/JobCardWrapper.java @@ -0,0 +1,28 @@ +package com.utopiaindustries.model.ctp; + +import java.util.ArrayList; +import java.util.List; + +public class JobCardWrapper { + + public JobCardWrapper(){ + this.items = new ArrayList<>(); + } + + private List items; + + public List getItems() { + return items; + } + + public void setItems(List items) { + this.items = items; + } + + @Override + public String toString() { + return "JobCardWrapper{" + + "items=" + items + + '}'; + } +} diff --git a/src/main/java/com/utopiaindustries/querybuilder/ctp/JobCardQueryBuilder.java b/src/main/java/com/utopiaindustries/querybuilder/ctp/JobCardQueryBuilder.java new file mode 100644 index 0000000..b4e05d2 --- /dev/null +++ b/src/main/java/com/utopiaindustries/querybuilder/ctp/JobCardQueryBuilder.java @@ -0,0 +1,55 @@ +package com.utopiaindustries.querybuilder.ctp; + +import com.utopiaindustries.querybuilder.QueryBuilder; +import com.utopiaindustries.util.CTPDateTimeFormat; +import com.utopiaindustries.util.StringUtils; + +import java.time.LocalDate; + +public class JobCardQueryBuilder { + + public static String buildQuery( String id, String code, String createdBy, String status, String inventoryStatus, String customer, String lotNumber, String purchaseOrderId, String locationSiteId, String startDate, String endDate, Long count ){ + // format date + String formattedDate; + String formattedEndDate; + String startDate1 = ""; + String endDate1 = ""; + if ( ! StringUtils.isNullOrEmpty( startDate ) ) { + formattedDate = CTPDateTimeFormat.getMySQLFormattedDateString( startDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT ); + formattedEndDate = CTPDateTimeFormat.getMySQLFormattedDateString( endDate, CTPDateTimeFormat.HTML5_DATE_INPUT_FORMAT ); + startDate1 = String.format( "'%s 00:00:01'", formattedDate ); + if ( ! StringUtils.isNullOrEmpty( endDate ) ) { + endDate1 = String.format("'%s 23:59:59'", formattedEndDate); + } + else { + endDate1 = String.format("'%s 23:59:59'", LocalDate.now() ); + } + } + + return ( new QueryBuilder() ) + .setTable( "cut_to_pack.job_card" ) + .setColumns( "*" ) + .where() + .columnEquals( "id", id ) + .and() + .columnEquals( "code", code ) + .and() + .columnEquals( "status", status ) + .and() + .columnEquals( "inventory_status", inventoryStatus ) + .and() + .columnEquals( "customer", customer ) + .and() + .columnEquals( "lot_number", lotNumber ) + .and() + .columnEquals( "purchase_order_id", purchaseOrderId ) + .and() + .columnEquals( "location_site_id", locationSiteId ) + .and() + .columnEqualToOrGreaterThan("created_at" , startDate1 ) + .and() + .columnEqualToOrLessThan( "created_at", endDate1 ) + .limit( count.intValue() ) + .build(); + } +} diff --git a/src/main/java/com/utopiaindustries/service/InventoryAccountService.java b/src/main/java/com/utopiaindustries/service/InventoryAccountService.java index 15bf46d..c0a6b60 100644 --- a/src/main/java/com/utopiaindustries/service/InventoryAccountService.java +++ b/src/main/java/com/utopiaindustries/service/InventoryAccountService.java @@ -123,4 +123,8 @@ public class InventoryAccountService { processIds.add(8L); return inventoryAccountDAO.findByIdsAndProcessIds( userInventoryAccountIds, processIds ); } + + public List getAllCuttingAccounts(){ + return inventoryAccountDAO.findByParentEntityTypeAndParentId( "PROCESS", 1L ); + } } diff --git a/src/main/java/com/utopiaindustries/service/InventoryService.java b/src/main/java/com/utopiaindustries/service/InventoryService.java index 2b3b9b6..ebbec03 100644 --- a/src/main/java/com/utopiaindustries/service/InventoryService.java +++ b/src/main/java/com/utopiaindustries/service/InventoryService.java @@ -28,7 +28,7 @@ public class InventoryService { private final FinishedItemDAO finishedItemDAO; private final StitchingOfflineItemDAO stitchingOfflineItemDAO; - public InventoryService(JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, BundleDAO bundleDAO, InventoryTransactionLegDAO inventoryTransactionLegDAO, InventoryTransactionDAO inventoryTransactionDAO, JobCardDAO jobCardDAO, CryptographyService cryptographyService, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) { + public InventoryService( JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, BundleDAO bundleDAO, InventoryTransactionLegDAO inventoryTransactionLegDAO, InventoryTransactionDAO inventoryTransactionDAO, JobCardDAO jobCardDAO, CryptographyService cryptographyService, MasterBundleDAO masterBundleDAO, FinishedItemDAO finishedItemDAO, StitchingOfflineItemDAO stitchingOfflineItemDAO) { this.jobCardItemDAO = jobCardItemDAO; this.cutPieceDAO = cutPieceDAO; this.bundleDAO = bundleDAO; @@ -41,60 +41,77 @@ public class InventoryService { this.stitchingOfflineItemDAO = stitchingOfflineItemDAO; } + private void updateJobCardInventoryStatus( JobCard card ){ + List items = jobCardItemDAO.findByCardId( card.getId( ) ); + for( JobCardItem item : items ){ + // check if item is received + if( item.getActualProduction( ) == null || item.getActualProduction( ).compareTo( BigDecimal.ZERO ) == 0 ){ + return; + } + } + card.setInventoryStatus( JobCard.InventoryStatus.RECEIVED.name( ) ); + jobCardDAO.save( card ); + } /* * receive inv from job card * */ - @Transactional(rollbackFor = Exception.class) - public void receiveJobCardInventory(long jobCardId, long accountId) { - if (jobCardId == 0 || accountId == 0) { - throw new RuntimeException("JobCard | Account can`t be empty"); + @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) + public void receiveJobCardInventory( long jobCardId, JobCardWrapper jobCardWrapper ) { + if ( jobCardId == 0 || jobCardWrapper.getItems( ) == null || jobCardWrapper.getItems( ).isEmpty( ) ) { + throw new RuntimeException( " JobCard can`t be empty"); } - JobCard jobCard = jobCardDAO.find(jobCardId); + JobCard jobCard = jobCardDAO.find( jobCardId ); // get job cad items - List items = jobCardItemDAO.findByCardId(jobCardId); - if (items != null && !items.isEmpty()) { - // get job card ite ids - List jobCardItemIds = items.stream() - .map(JobCardItem::getId) - .collect(Collectors.toList()); + List jobCardItemWrappers = jobCardWrapper.getItems( ); + List jobCardItemWrapperIds = jobCardItemWrappers.stream( ) + .map( JobCardItemWrapper::getJobCardItemId ) + .collect( Collectors.toList( ) ); - // id to item map - Map idToItemMap = items.stream() - .collect(Collectors.toMap(JobCardItem::getId, Function.identity())); + Map jobCardItemIdToActualProdMap = jobCardItemWrappers.stream( ) + .collect( Collectors.toMap( JobCardItemWrapper::getJobCardItemId, JobCardItemWrapper::getActualProduction ) ); - Map> piecesMap = cutPieceDAO.findByJobCardItemIds(jobCardItemIds) - .stream() - .collect(Collectors.groupingBy(CutPiece::getJobCardItemId)); + List items = jobCardItemDAO.findByIds( jobCardItemWrapperIds ); + if ( items != null && !items.isEmpty( ) ) { + // get job card item ids + List jobCardItemIds = items.stream( ) + .map( JobCardItem::getId) + .collect( Collectors.toList( )); - // populate map - Map> jobCardItemtoPiecesMap = new HashMap<>(); - for (JobCardItem jobCardItem : items) { - if (!jobCardItemtoPiecesMap.containsKey(jobCardItem)) { - jobCardItemtoPiecesMap.put(jobCardItem, piecesMap.getOrDefault(jobCardItem.getId(), new ArrayList<>())); - } + // save updated cut pieces + List cutPieces = jobCardItemWrappers.stream( ) + .flatMap( wrapper -> wrapper.getPieces( ).stream( ) ) + .collect( Collectors.toList( ) ); + cutPieceDAO.saveAll( cutPieces ); + + Map> piecesMap = cutPieceDAO.findByJobCardItemIds( jobCardItemIds) + .stream( ) + .collect( Collectors.groupingBy( CutPiece::getJobCardItemId)); + + for ( JobCardItem jobCardItem : items) { + // create + save bundles + List bundles = createBundles( jobCardItem, piecesMap.get( jobCardItem.getId( ) ) ); + // create transactions + createTransactions( bundles, jobCardItem.getAccountId( ), InventoryArtifactType.BUNDLE.name( )); + jobCardItem.setActualProduction( jobCardItemIdToActualProdMap.getOrDefault( jobCardItem.getId( ) , BigDecimal.ZERO ) ); } - - // create + save bundles - List bundles = createBundles(jobCardId, jobCardItemtoPiecesMap); - // create transactions - createTransactions(bundles, accountId, InventoryArtifactType.BUNDLE.name()); + // update items with quantity + jobCardItemDAO.saveAll( items ); // update job card inv status - jobCard.setInventoryStatus(JobCard.InventoryStatus.RECEIVED.name()); - jobCardDAO.save(jobCard); + updateJobCardInventoryStatus( jobCard ); } else { - throw new RuntimeException("Items Not found in Job Card"); + throw new RuntimeException( "Items Not found in Job Card"); } } /* * t create transactions * */ - private void createTransactions(List artifacts, long accountId, String parentDocumentType) { - if (!artifacts.isEmpty()) { - InventoryTransaction transaction = createInventoryTransaction("Transaction Against " + parentDocumentType); - for (InventoryArtifact artifact : artifacts) { - InventoryTransactionLeg leg = createInventoryTransactionLeg(transaction, artifact, accountId, InventoryTransactionLeg.Type.IN.name(), parentDocumentType); + private void createTransactions( List artifacts, long accountId, String parentDocumentType) { + if ( !artifacts.isEmpty( )) { + InventoryTransaction transaction = createInventoryTransaction( "Transaction Against " + parentDocumentType); + for ( InventoryArtifact artifact : artifacts) { + InventoryTransactionLeg leg = createInventoryTransactionLeg( transaction, artifact, accountId, InventoryTransactionLeg.Type.IN.name( ), parentDocumentType ); } } } @@ -103,167 +120,169 @@ public class InventoryService { /* * create and save transaction * */ - private InventoryTransaction createInventoryTransaction(String notes) { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - InventoryTransaction transaction = new InventoryTransaction(); - transaction.setGeneratedBy(authentication.getName()); - transaction.setTransactionDateTime(LocalDateTime.now()); - transaction.setNotes(notes); - transaction.setId(inventoryTransactionDAO.save(transaction)); + private InventoryTransaction createInventoryTransaction( String notes) { + Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); + InventoryTransaction transaction = new InventoryTransaction( ); + transaction.setGeneratedBy( authentication.getName( )); + transaction.setTransactionDateTime( LocalDateTime.now( )); + transaction.setNotes( notes); + transaction.setId( inventoryTransactionDAO.save( transaction)); return transaction; } /* * create and save inventory transaction * */ - private InventoryTransactionLeg createInventoryTransactionLeg(InventoryTransaction transaction, + private InventoryTransactionLeg createInventoryTransactionLeg( InventoryTransaction transaction, InventoryArtifact artifact, long accountId, String transactionType, String parentDocumentType) { - InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg(); - inventoryTransactionLeg.setTransactionId(transaction.getId()); - inventoryTransactionLeg.setType(transactionType); - inventoryTransactionLeg.setQuantity(BigDecimal.valueOf(1L)); - inventoryTransactionLeg.setAccountId((int) accountId); - inventoryTransactionLeg.setItemId(artifact.getItemId()); - inventoryTransactionLeg.setSku(artifact.getSku()); - inventoryTransactionLeg.setParentDocumentType(parentDocumentType); - inventoryTransactionLeg.setParentDocumentId(artifact.getId()); - inventoryTransactionLeg.setParentDocumentPieceType(artifact.getType()); - inventoryTransactionLeg.setTransactionLegDateTime(LocalDateTime.now()); + InventoryTransactionLeg inventoryTransactionLeg = new InventoryTransactionLeg( ); + inventoryTransactionLeg.setTransactionId( transaction.getId( )); + inventoryTransactionLeg.setType( transactionType); + inventoryTransactionLeg.setQuantity( BigDecimal.valueOf( 1L)); + inventoryTransactionLeg.setAccountId( ( int) accountId); + inventoryTransactionLeg.setItemId( artifact.getItemId( )); + inventoryTransactionLeg.setSku( artifact.getSku( )); + inventoryTransactionLeg.setParentDocumentType( parentDocumentType); + inventoryTransactionLeg.setParentDocumentId( artifact.getId( )); + inventoryTransactionLeg.setParentDocumentPieceType( artifact.getType( )); + inventoryTransactionLeg.setTransactionLegDateTime( LocalDateTime.now( )); // set balance - BigDecimal initialBalance = calculateBalance(accountId, artifact.getItemId(), parentDocumentType, artifact.getType()); + BigDecimal initialBalance = calculateBalance( accountId, artifact.getItemId( ), parentDocumentType, artifact.getType( )); - if (transactionType.equalsIgnoreCase(InventoryTransactionLeg.Type.IN.name())) { - initialBalance = initialBalance.add(inventoryTransactionLeg.getQuantity()); + if ( transactionType.equalsIgnoreCase( InventoryTransactionLeg.Type.IN.name( ))) { + initialBalance = initialBalance.add( inventoryTransactionLeg.getQuantity( )); } else { - initialBalance = initialBalance.subtract(inventoryTransactionLeg.getQuantity()); + initialBalance = initialBalance.subtract( inventoryTransactionLeg.getQuantity( )); } - inventoryTransactionLeg.setBalance(initialBalance); - inventoryTransactionLeg.setId(inventoryTransactionLegDAO.save(inventoryTransactionLeg)); + inventoryTransactionLeg.setBalance( initialBalance); + inventoryTransactionLeg.setId( inventoryTransactionLegDAO.save( inventoryTransactionLeg)); return inventoryTransactionLeg; } // calculate balance - private BigDecimal calculateBalance(long accountId, long itemId, String parentType, String pieceType) { + private BigDecimal calculateBalance( long accountId, long itemId, String parentType, String pieceType) { // find the last transaction leg of the current account Id with itemId - InventoryTransactionLeg lastTransactionLeg = inventoryTransactionLegDAO.findLastByAccountIdAndItemIdAndParentType(accountId, itemId, parentType, pieceType); - if (lastTransactionLeg.getBalance() != null) { - return lastTransactionLeg.getBalance(); + InventoryTransactionLeg lastTransactionLeg = inventoryTransactionLegDAO.findLastByAccountIdAndItemIdAndParentType( accountId, itemId, parentType, pieceType); + if ( lastTransactionLeg.getBalance( ) != null) { + return lastTransactionLeg.getBalance( ); } return BigDecimal.ZERO; } // create bundles from cut pieces - private List createBundles(long jobCardId, Map> jobCardItemtoPiecesMap) { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - if (jobCardItemtoPiecesMap != null && !jobCardItemtoPiecesMap.isEmpty()) { - List bundles = new ArrayList<>(); - for (Map.Entry> entry : jobCardItemtoPiecesMap.entrySet()) { - JobCardItem key = entry.getKey(); - List value = entry.getValue(); - // create bundle against every cut piece - for (CutPiece cutPiece : value) { - Bundle bundle = new Bundle(); - bundle.setItemId(key.getItemId()); - bundle.setSku(key.getSku()); - bundle.setJobCardId(jobCardId); - bundle.setWrapQuantity(cutPiece.getQuantity()); - bundle.setType(cutPiece.getType()); - bundle.setCreatedAt(LocalDateTime.now()); - bundle.setCreatedBy(authentication.getName()); - bundles.add(bundle); - bundle.setId(bundleDAO.save(bundle)); - bundle.setBarcode(cryptographyService.generateRandomString(15)); - // save again after barcode generation - bundle.setId(bundleDAO.save(bundle)); - } - + private List createBundles( JobCardItem jobCardItem, + List jobCardItemPieces ) { + Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); + if ( jobCardItemPieces != null && !jobCardItemPieces.isEmpty( )) { + List bundles = new ArrayList<>( ); + // create bundle against every cut piece + for ( CutPiece cutPiece : jobCardItemPieces ) { + Bundle bundle = new Bundle( ); + bundle.setItemId( jobCardItem.getItemId( )); + bundle.setSku( jobCardItem.getSku( )); + bundle.setJobCardId( jobCardItem.getJobCardId( ) ); + bundle.setWrapQuantity( cutPiece.getQuantity( )); + bundle.setType( cutPiece.getType( )); + bundle.setCreatedAt( LocalDateTime.now( )); + bundle.setCreatedBy( authentication.getName( )); + bundles.add( bundle); + bundle.setId( bundleDAO.save( bundle)); + bundle.setBarcode( cryptographyService.generateRandomString( 15)); + // save again after barcode generation + bundle.setId( bundleDAO.save( bundle)); } + +// for ( Map.Entry> entry : jobCardItemPieces ) { +// JobCardItem key = entry.getKey( ); +// List value = entry.getValue( ); +// +// +// } return bundles; } - return new ArrayList<>(); + return new ArrayList<>( ); } /* * receive inventory from master barcode * */ - @Transactional(rollbackFor = Exception.class) - public void receiveInventoryFromMasterBarcode(long masterId, long toAccount) { - if (masterId == 0 || toAccount == 0) { - throw new RuntimeException("Master Barcode | Account can`t be empty"); + @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) + public void receiveInventoryFromMasterBarcode( long masterId, long toAccount) { + if ( masterId == 0 || toAccount == 0) { + throw new RuntimeException( "Master Barcode | Account can`t be empty"); } - MasterBundle masterBundle = masterBundleDAO.find(masterId); + MasterBundle masterBundle = masterBundleDAO.find( masterId); // find bundles from master barcode - List bundles = bundleDAO.findByMasterId(masterId); - if (bundles != null && !bundles.isEmpty()) { + List bundles = bundleDAO.findByMasterId( masterId); + if ( bundles != null && !bundles.isEmpty( )) { // bundle ids - List bundleIds = bundles.stream().map(Bundle::getId).collect(Collectors.toList()); + List bundleIds = bundles.stream( ).map( Bundle::getId).collect( Collectors.toList( )); Map lastBundleIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), bundleIds, InventoryArtifactType.BUNDLE.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), bundleIds, InventoryArtifactType.BUNDLE.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); // create Transaction - InventoryTransaction transaction = createInventoryTransaction("Against Movement from Cutting to Stitching"); - inventoryTransactionDAO.save(transaction); + InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Cutting to Stitching"); + inventoryTransactionDAO.save( transaction); // create transaction legs - for (Bundle bundle : bundles) { - InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(bundle.getId(), null); - if (lastInvTransaction != null) { + for ( Bundle bundle : bundles) { + InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( bundle.getId( ), null); + if ( lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.BUNDLE.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.BUNDLE.name( )); // IN - createInventoryTransactionLeg(transaction, bundle, toAccount, InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.BUNDLE.name()); + createInventoryTransactionLeg( transaction, bundle, toAccount, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.BUNDLE.name( )); } } // update status - masterBundle.setIsReceived(true); - masterBundleDAO.save(masterBundle); + masterBundle.setIsReceived( true); + masterBundleDAO.save( masterBundle); } } - private void validateItems(List cardItems) { - if (cardItems == null || cardItems.isEmpty()) { - throw new RuntimeException("Item cant be Empty | null"); + private void validateItems( List cardItems) { + if ( cardItems == null || cardItems.isEmpty( )) { + throw new RuntimeException( "Item cant be Empty | null"); } - for (JobCardItem jobCardItem : cardItems) { - int finalQuantity = jobCardItem.getExpectedProductionQuantity().compareTo(jobCardItem.getTotalProduction().add(jobCardItem.getProduction())); - if (finalQuantity < 0) { - throw new RuntimeException(" Items cant be generated because it exceeds from limit of expected Production"); + for ( JobCardItem jobCardItem : cardItems) { + int finalQuantity = jobCardItem.getActualProduction( ).compareTo( jobCardItem.getTotalProduction( ).add( jobCardItem.getProduction( ))); + if ( finalQuantity < 0) { + throw new RuntimeException( " Items cant be generated because it exceeds from limit of expected Production"); } } } - private void checkAllBundleAreReceived(long jobCardId, + private void checkAllBundleAreReceived( long jobCardId, List jobCardItems) { - if (jobCardItems != null && !jobCardItems.isEmpty()) { - List itemIds = jobCardItems.stream().map(JobCardItem::getItemId).collect(Collectors.toList()); - List bundles = bundleDAO.findByItemIdsAndCardId(itemIds, jobCardId); - List masterBundleIds = bundles.stream().map(Bundle::getMasterBundleId).collect(Collectors.toList()); -// Map> ItemIdCardIdToBundlesMap = bundles -// .stream() -// .collect( Collectors.groupingBy( e-> e.getItemId() + "-" + e.getJobCardId() ) ); + if ( jobCardItems != null && !jobCardItems.isEmpty( ) ) { + List itemIds = jobCardItems.stream( ) + .filter( JobCardItem::getIsSelected ) + .map( JobCardItem::getItemId).collect( Collectors.toList( )); + List bundles = bundleDAO.findByItemIdsAndCardId( itemIds, jobCardId); + List masterBundleIds = bundles.stream( ).map( Bundle::getMasterBundleId).collect( Collectors.toList( )); + + Map idToMasterBundleMap = masterBundleDAO.findByIds( masterBundleIds) + .stream( ) + .collect( Collectors.toMap( MasterBundle::getId, Function.identity( ))); - Map idToMasterBundleMap = masterBundleDAO.findByIds(masterBundleIds) - .stream() - .collect(Collectors.toMap(MasterBundle::getId, Function.identity())); - - for (Bundle bundle : bundles) { + for ( Bundle bundle : bundles) { // check all bundles are received - MasterBundle masterBundle = idToMasterBundleMap.getOrDefault(bundle.getMasterBundleId(), null); - if (masterBundle == null || !masterBundle.getIsReceived()) { - throw new RuntimeException("Please Receive Bundles Against Master Bundles First to Create Finished Item"); + MasterBundle masterBundle = idToMasterBundleMap.getOrDefault( bundle.getMasterBundleId( ), null); + if ( masterBundle == null || ! masterBundle.getIsReceived( ) ) { + throw new RuntimeException( "Please Receive Bundles Against Master Bundles First to Create Finished Item"); } } } @@ -272,76 +291,76 @@ public class InventoryService { /* * create finished items from master bundles * */ - @Transactional(rollbackFor = Exception.class) - public void createStitchingOfflineItemsFromJobCard(JobCard jobCard) { - List jobCardItems = jobCard.getItems(); - List updatedItems = new ArrayList<>(); + @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) + public void createStitchingOfflineItemsFromJobCard( JobCard jobCard) { + List jobCardItems = jobCard.getItems( ); + List updatedItems = new ArrayList<>( ); // validate items - validateItems(jobCardItems); + validateItems( jobCardItems); // check whether all bundles are received against finish goods - checkAllBundleAreReceived(jobCard.getId(), jobCardItems); - for (JobCardItem item : jobCardItems) { + checkAllBundleAreReceived( jobCard.getId( ), jobCardItems); + for ( JobCardItem item : jobCardItems) { // select which has inventory - if (!item.getProduction().equals(BigDecimal.ZERO)) { + if ( item.getProduction( ).compareTo( BigDecimal.ZERO ) != 0 ) { // production is completed out bundles - if (item.getExpectedProductionQuantity().compareTo(item.getTotalProduction().add(item.getProduction())) == 0) { + if ( item.getActualProduction( ).compareTo( item.getTotalProduction( ).add( item.getProduction( ))) == 0) { // create out transactions of bundles in master bundles - List bundles = bundleDAO.findByItemIdAndCardId(item.getItemId(), jobCard.getId()); - if (bundles != null && !bundles.isEmpty()) { + List bundles = bundleDAO.findByItemIdAndCardId( item.getItemId( ), jobCard.getId( )); + if ( bundles != null && !bundles.isEmpty( )) { // bundle ids - List bundleIds = bundles.stream().map(Bundle::getId).collect(Collectors.toList()); + List bundleIds = bundles.stream( ).map( Bundle::getId).collect( Collectors.toList( )); Map lastBundleIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), bundleIds, InventoryArtifactType.BUNDLE.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), bundleIds, InventoryArtifactType.BUNDLE.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); // create Transaction - InventoryTransaction transaction = createInventoryTransaction("Against Movement from Stitching to Stitched Offline Item"); - inventoryTransactionDAO.save(transaction); + InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Stitching to Stitched Offline Item"); + inventoryTransactionDAO.save( transaction); // create transaction legs - for (Bundle bundle : bundles) { - InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(bundle.getId(), null); - if (lastInvTransaction != null) { + for ( Bundle bundle : bundles) { + InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( bundle.getId( ), null); + if ( lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.BUNDLE.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, bundle, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.BUNDLE.name( )); } } } } // create finished items - List stitchingOfflineItems = createStitchingOfflineItems(item); + List stitchingOfflineItems = createStitchingOfflineItems( item); // create IN Transactions of Finished Items into account - createTransactions(stitchingOfflineItems, jobCard.getToAccountId(), InventoryArtifactType.STITCHING_OFFLINE.name()); - item.setTotalProduction(item.getTotalProduction().add(item.getProduction())); - item.setJobCardId(jobCard.getId()); - updatedItems.add(item); + createTransactions( stitchingOfflineItems, jobCard.getToAccountId( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); + item.setTotalProduction( item.getTotalProduction( ).add( item.getProduction( ))); + item.setJobCardId( jobCard.getId( )); + updatedItems.add( item); } } // save all - jobCardItemDAO.saveAll(updatedItems); + jobCardItemDAO.saveAll( updatedItems); } /* * create finished items * */ - public List createStitchingOfflineItems(JobCardItem jobCardItem) { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); - List items = new ArrayList<>(); - if (jobCardItem != null) { - for (int i = 1; i <= jobCardItem.getProduction().intValue(); i++) { - StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem(); - stitchingOfflineItem.setCreatedAt(LocalDateTime.now()); - stitchingOfflineItem.setCreatedBy(authentication.getName()); - stitchingOfflineItem.setItemId(jobCardItem.getItemId()); - stitchingOfflineItem.setSku(jobCardItem.getSku()); - stitchingOfflineItem.setJobCardId(jobCardItem.getId()); - stitchingOfflineItem.setIsQa(true); - long id = stitchingOfflineItemDAO.save(stitchingOfflineItem); - stitchingOfflineItem.setId(id); - stitchingOfflineItem.setBarcode(cryptographyService.generateRandomString(15)); - stitchingOfflineItemDAO.save(stitchingOfflineItem); - items.add(stitchingOfflineItem); + public List createStitchingOfflineItems( JobCardItem jobCardItem) { + Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); + List items = new ArrayList<>( ); + if ( jobCardItem != null) { + for ( int i = 1; i <= jobCardItem.getProduction( ).intValue( ); i++) { + StitchingOfflineItem stitchingOfflineItem = new StitchingOfflineItem( ); + stitchingOfflineItem.setCreatedAt( LocalDateTime.now( )); + stitchingOfflineItem.setCreatedBy( authentication.getName( )); + stitchingOfflineItem.setItemId( jobCardItem.getItemId( )); + stitchingOfflineItem.setSku( jobCardItem.getSku( )); + stitchingOfflineItem.setJobCardId( jobCardItem.getId( )); + stitchingOfflineItem.setIsQa( false ); + long id = stitchingOfflineItemDAO.save( stitchingOfflineItem); + stitchingOfflineItem.setId( id); + stitchingOfflineItem.setBarcode( cryptographyService.generateRandomString( 15)); + stitchingOfflineItemDAO.save( stitchingOfflineItem); + items.add( stitchingOfflineItem); } } return items; @@ -350,51 +369,51 @@ public class InventoryService { /* * find transactions by account id * */ - public List findTransactionByAccountId(long accountId) { - List legs = inventoryTransactionLegDAO.findByAccountId(accountId); + public List findTransactionByAccountId( long accountId) { + List legs = inventoryTransactionLegDAO.findByAccountId( accountId); - List tIds = legs.stream().map(InventoryTransactionLeg::getTransactionId).collect(Collectors.toList()); - Map idToTransactioMap = inventoryTransactionDAO.findByIds(tIds).stream().collect(Collectors.toMap(InventoryTransaction::getId, Function.identity())); - legs.forEach(leg -> leg.setTransaction(idToTransactioMap.get(leg.getTransactionId()))); + List tIds = legs.stream( ).map( InventoryTransactionLeg::getTransactionId).collect( Collectors.toList( )); + Map idToTransactioMap = inventoryTransactionDAO.findByIds( tIds).stream( ).collect( Collectors.toMap( InventoryTransaction::getId, Function.identity( ))); + legs.forEach( leg -> leg.setTransaction( idToTransactioMap.get( leg.getTransactionId( )))); return legs; } /* * * */ - @Transactional(rollbackFor = Exception.class) - public void markFinishedItemsApproved(List fItemIds, long toAccount) { + @Transactional( rollbackFor = Exception.class) + public void markFinishedItemsApproved( List fItemIds, long toAccount) { - if (fItemIds.isEmpty() || toAccount == 0) { - throw new RuntimeException("Finished Item Ids | Account can`t be empty"); + if ( fItemIds.isEmpty( ) || toAccount == 0) { + throw new RuntimeException( "Finished Item Ids | Account can`t be empty"); } - List finishedItems = finishedItemDAO.findByIds(fItemIds); - if (finishedItems != null && !finishedItems.isEmpty()) { + List finishedItems = finishedItemDAO.findByIds( fItemIds); + if ( finishedItems != null && !finishedItems.isEmpty( )) { // bundle ids - List finishedItemIds = finishedItems.stream().map(FinishedItem::getId).collect(Collectors.toList()); + List finishedItemIds = finishedItems.stream( ).map( FinishedItem::getId).collect( Collectors.toList( )); Map lastBundleIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); // create Transaction - InventoryTransaction transaction = createInventoryTransaction("Against Movement from Stitching to Packaging After QA"); - inventoryTransactionDAO.save(transaction); + InventoryTransaction transaction = createInventoryTransaction( "Against Movement from Stitching to Packaging After QA"); + inventoryTransactionDAO.save( transaction); // create transaction legs - for (FinishedItem finishedItem : finishedItems) { - InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault(finishedItem.getId(), null); - if (lastInvTransaction != null) { + for ( FinishedItem finishedItem : finishedItems) { + InventoryTransactionLeg lastInvTransaction = lastBundleIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); + if ( lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCHING_OFFLINE.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); // IN - createInventoryTransactionLeg(transaction, finishedItem, toAccount, InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.STITCHING_OFFLINE.name()); + createInventoryTransactionLeg( transaction, finishedItem, toAccount, InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); } - finishedItem.setIsQa(true); + finishedItem.setIsQa( true); } - finishedItemDAO.saveAll(finishedItems); + finishedItemDAO.saveAll( finishedItems); } } @@ -402,81 +421,81 @@ public class InventoryService { /* * generate finished items against stitched items * */ - @Transactional(rollbackFor = Exception.class) - public void createFinishedItemsAgainstStitchedItems( StitchedItemWrapper wrapper ) { - if (wrapper.getItems() != null && wrapper.getFinishedAccountId() != 0) { - Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + @Transactional( rollbackFor = Exception.class) + public void createFinishedItemsAgainstStitchedItems( StitchedItemWrapper wrapper ) { + if ( wrapper.getItems( ) != null && wrapper.getFinishedAccountId( ) != 0) { + Authentication authentication = SecurityContextHolder.getContext( ).getAuthentication( ); - List stitchingOfflineItems = wrapper.getItems(); - List updatedStitchedItems = new ArrayList<>(); - List finishedItems = new ArrayList<>(); + List stitchingOfflineItems = wrapper.getItems( ); + List updatedStitchedItems = new ArrayList<>( ); + List finishedItems = new ArrayList<>( ); - List stitchedItemIds = stitchingOfflineItems.stream() - .map(StitchingOfflineItem::getId) - .collect(Collectors.toList()); + List stitchedItemIds = stitchingOfflineItems.stream( ) + .map( StitchingOfflineItem::getId) + .collect( Collectors.toList( )); Map lastStitchedIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); // get finished items from stitched items i f exists - List preCreatedFinishedItemIds = finishedItemDAO.findByStitchedItemIds( stitchedItemIds ).stream(). - map( FinishedItem::getId ).collect(Collectors.toList()); + List preCreatedFinishedItemIds = finishedItemDAO.findByStitchedItemIds( stitchedItemIds ).stream( ). + map( FinishedItem::getId ).collect( Collectors.toList( )); Map lastFinishedItemInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), preCreatedFinishedItemIds, InventoryArtifactType.FINISHED_ITEM.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), preCreatedFinishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); - InventoryTransaction transaction = createInventoryTransaction("Against Movement From Stitching Offline to Finished Item"); + InventoryTransaction transaction = createInventoryTransaction( "Against Movement From Stitching Offline to Finished Item"); // generate FI for SI - for (StitchingOfflineItem stitchingOfflineItem : stitchingOfflineItems) { - if (stitchingOfflineItem.getQaStatus().equalsIgnoreCase("APPROVED" )) { + for ( StitchingOfflineItem stitchingOfflineItem : stitchingOfflineItems) { + if ( stitchingOfflineItem.getQaStatus( ).equalsIgnoreCase( "APPROVED" )) { // check finished item is already created - FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem(stitchingOfflineItem.getId()); - if (preCreatedItem == null) { - FinishedItem finishedItem = new FinishedItem(); - finishedItem.setItemId(stitchingOfflineItem.getItemId()); - finishedItem.setSku(stitchingOfflineItem.getSku()); - finishedItem.setBarcode(stitchingOfflineItem.getBarcode()); - finishedItem.setCreatedBy(authentication.getName()); - finishedItem.setCreatedAt(LocalDateTime.now()); - finishedItem.setStitchedItemId(stitchingOfflineItem.getId()); - finishedItem.setJobCardId(stitchingOfflineItem.getJobCardId()); - finishedItem.setIsQa(false); - finishedItem.setId(finishedItemDAO.save(finishedItem)); - finishedItems.add(finishedItem); - InventoryTransactionLeg lastInvTransaction = lastStitchedIdInTransactionMap.getOrDefault(stitchingOfflineItem.getId(), null); - if ( lastInvTransaction != null ) { + FinishedItem preCreatedItem = finishedItemDAO.findByStitchedItem( stitchingOfflineItem.getId( )); + if ( preCreatedItem == null) { + FinishedItem finishedItem = new FinishedItem( ); + finishedItem.setItemId( stitchingOfflineItem.getItemId( )); + finishedItem.setSku( stitchingOfflineItem.getSku( )); + finishedItem.setBarcode( stitchingOfflineItem.getBarcode( )); + finishedItem.setCreatedBy( authentication.getName( )); + finishedItem.setCreatedAt( LocalDateTime.now( )); + finishedItem.setStitchedItemId( stitchingOfflineItem.getId( )); + finishedItem.setJobCardId( stitchingOfflineItem.getJobCardId( )); + finishedItem.setIsQa( false); + finishedItem.setId( finishedItemDAO.save( finishedItem)); + finishedItems.add( finishedItem); + InventoryTransactionLeg lastInvTransaction = lastStitchedIdInTransactionMap.getOrDefault( stitchingOfflineItem.getId( ), null); + if ( lastInvTransaction != null ) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.STITCHING_OFFLINE.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.STITCHING_OFFLINE.name( )); } // update stitched item - stitchingOfflineItem.setIsQa(true); + stitchingOfflineItem.setIsQa( true); // if FI is already created } else { // create OUT from stitching account Finished Item - InventoryTransactionLeg lastInvTransaction = lastFinishedItemInTransactionMap.getOrDefault( preCreatedItem.getId(), null); - if ( lastInvTransaction != null ) { + InventoryTransactionLeg lastInvTransaction = lastFinishedItemInTransactionMap.getOrDefault( preCreatedItem.getId( ), null); + if ( lastInvTransaction != null ) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, stitchingOfflineItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); } // create IN in finishing Account Finished Item - finishedItems.add( preCreatedItem ); + finishedItems.add( preCreatedItem ); } } } - for (FinishedItem finishedItem : finishedItems) { + for ( FinishedItem finishedItem : finishedItems) { // IN - createInventoryTransactionLeg(transaction, finishedItem, wrapper.getFinishedAccountId(), InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.FINISHED_ITEM.name()); + createInventoryTransactionLeg( transaction, finishedItem, wrapper.getFinishedAccountId( ), InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); } // save updated stitched items - stitchingOfflineItemDAO.saveAll(wrapper.getItems()); + stitchingOfflineItemDAO.saveAll( wrapper.getItems( )); } } @@ -484,39 +503,39 @@ public class InventoryService { /* * segregate finish items * */ - @Transactional(rollbackFor = Exception.class) - public void segregateFinishedItems(FinishedItemWrapper wrapper) { - if (wrapper != null && wrapper.getItems() != null) { + @Transactional( rollbackFor = Exception.class, propagation = Propagation.NESTED ) + public void segregateFinishedItems( FinishedItemWrapper wrapper) { + if ( wrapper != null && wrapper.getItems( ) != null) { - List items = wrapper.getItems(); - List updatedItems = new ArrayList<>(); + List items = wrapper.getItems( ); + List updatedItems = new ArrayList<>( ); // finished ids - List finishedItemIds = items.stream().map(FinishedItem::getId) - .collect(Collectors.toList()); + List finishedItemIds = items.stream( ).map( FinishedItem::getId) + .collect( Collectors.toList( )); // stitched ids - List stitchedItemIds = items.stream().map(FinishedItem::getStitchedItemId) - .collect(Collectors.toList()); + List stitchedItemIds = items.stream( ).map( FinishedItem::getStitchedItemId) + .collect( Collectors.toList( )); // create parent doc type last IN transaction map Map lastFinishedItemIdInTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.IN.name(), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.IN.name( ), finishedItemIds, InventoryArtifactType.FINISHED_ITEM.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); // create parent doc type last OUT transaction map Map lastStitchedItemOutTransactionMap = inventoryTransactionLegDAO - .findLastTransactionByParentIdAndParentType(InventoryTransactionLeg.Type.OUT.name(), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name()) - .stream() - .collect(Collectors.toMap(InventoryTransactionLeg::getParentDocumentId, Function.identity())); + .findLastTransactionByParentIdAndParentType( InventoryTransactionLeg.Type.OUT.name( ), stitchedItemIds, InventoryArtifactType.STITCHING_OFFLINE.name( )) + .stream( ) + .collect( Collectors.toMap( InventoryTransactionLeg::getParentDocumentId, Function.identity( ))); // create transaction - InventoryTransaction transaction = createInventoryTransaction("Against Segregation of Finished Items"); + InventoryTransaction transaction = createInventoryTransaction( "Against Segregation of Finished Items"); // create IN and OUT for all approved items - for (FinishedItem finishedItem : items) { - InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault(finishedItem.getId(), null); - finishedItem.setIsQa(true); + for ( FinishedItem finishedItem : items) { + InventoryTransactionLeg lastInvTransaction = lastFinishedItemIdInTransactionMap.getOrDefault( finishedItem.getId( ), null); + finishedItem.setIsQa( true); /* * item is not approved and washed is selected then item remain in Finishing account * */ @@ -524,37 +543,37 @@ public class InventoryService { /* * item is approved and alter is selected then finished item will to stitching account * */ - if (finishedItem.getQaStatus().equalsIgnoreCase("ALTER")) { + if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "ALTER")) { // create OUT and IN transactions for FI - if (lastInvTransaction != null) { + if ( lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); // IN // get the stitching account id - long stitchedItemId = finishedItem.getStitchedItemId(); - InventoryTransactionLeg lastOutTransaction = lastStitchedItemOutTransactionMap.getOrDefault(stitchedItemId, null); - createInventoryTransactionLeg(transaction, finishedItem, lastOutTransaction.getAccountId(), InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.FINISHED_ITEM.name()); + long stitchedItemId = finishedItem.getStitchedItemId( ); + InventoryTransactionLeg lastOutTransaction = lastStitchedItemOutTransactionMap.getOrDefault( stitchedItemId, null); + createInventoryTransactionLeg( transaction, finishedItem, lastOutTransaction.getAccountId( ), InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); } } /* * item is approved and grade is selected then fI is move to grade account */ - if (finishedItem.getQaStatus().equalsIgnoreCase("APPROVED") && finishedItem.getAccountId() != 0) { + if ( finishedItem.getQaStatus( ).equalsIgnoreCase( "APPROVED") && finishedItem.getAccountId( ) != 0) { // create OUT and IN transactions for FI - if (lastInvTransaction != null) { + if ( lastInvTransaction != null) { // OUT - long fromAccount = lastInvTransaction.getAccountId(); - createInventoryTransactionLeg(transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name(), InventoryArtifactType.FINISHED_ITEM.name()); + long fromAccount = lastInvTransaction.getAccountId( ); + createInventoryTransactionLeg( transaction, finishedItem, fromAccount, InventoryTransactionLeg.Type.OUT.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); // IN - createInventoryTransactionLeg(transaction, finishedItem, finishedItem.getAccountId(), InventoryTransactionLeg.Type.IN.name(), InventoryArtifactType.FINISHED_ITEM.name()); + createInventoryTransactionLeg( transaction, finishedItem, finishedItem.getAccountId( ), InventoryTransactionLeg.Type.IN.name( ), InventoryArtifactType.FINISHED_ITEM.name( )); } - finishedItem.setIsSegregated(true); + finishedItem.setIsSegregated( true); } - updatedItems.add(finishedItem); + updatedItems.add( finishedItem); } - finishedItemDAO.saveAll(updatedItems); + finishedItemDAO.saveAll( updatedItems); // save finish items } } @@ -562,7 +581,7 @@ public class InventoryService { /* * find item summary by account * */ - public List findItemSummaryByAccountId(long accountId) { - return inventoryTransactionLegDAO.findSummaryByAccountId(accountId); + public List findItemSummaryByAccountId( long accountId) { + return inventoryTransactionLegDAO.findSummaryByAccountId( accountId); } } diff --git a/src/main/java/com/utopiaindustries/service/JobCardService.java b/src/main/java/com/utopiaindustries/service/JobCardService.java index fb9fa24..93b9d70 100644 --- a/src/main/java/com/utopiaindustries/service/JobCardService.java +++ b/src/main/java/com/utopiaindustries/service/JobCardService.java @@ -1,17 +1,12 @@ package com.utopiaindustries.service; -import com.utopiaindustries.dao.ctp.CutPieceDAO; -import com.utopiaindustries.dao.ctp.CutPieceTypeDAO; -import com.utopiaindustries.dao.ctp.JobCardDAO; -import com.utopiaindustries.dao.ctp.JobCardItemDAO; +import com.utopiaindustries.dao.ctp.*; import com.utopiaindustries.dao.uind.ItemDAO; import com.utopiaindustries.dao.uind.LocationSiteDAO; import com.utopiaindustries.dao.uind.PurchaseOrderDAO; -import com.utopiaindustries.model.ctp.CutPiece; -import com.utopiaindustries.model.ctp.CutPieceType; -import com.utopiaindustries.model.ctp.JobCard; -import com.utopiaindustries.model.ctp.JobCardItem; +import com.utopiaindustries.model.ctp.*; import com.utopiaindustries.model.uind.Item; +import com.utopiaindustries.querybuilder.ctp.JobCardQueryBuilder; import com.utopiaindustries.util.StringUtils; import org.springframework.security.core.Authentication; import org.springframework.security.core.context.SecurityContextHolder; @@ -35,8 +30,9 @@ public class JobCardService { private final ItemDAO itemDAO; private final LocationSiteDAO locationSiteDAO; private final PurchaseOrderDAO purchaseOrderDAO; + private final UserInventoryAccountDAO userInventoryAccountDAO; - public JobCardService(JobCardDAO jobCardDAO, CutPieceTypeDAO cutPieceTypeDAO, JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, ItemDAO itemDAO, LocationSiteDAO locationSiteDAO, PurchaseOrderDAO purchaseOrderDAO) { + public JobCardService(JobCardDAO jobCardDAO, CutPieceTypeDAO cutPieceTypeDAO, JobCardItemDAO jobCardItemDAO, CutPieceDAO cutPieceDAO, ItemDAO itemDAO, LocationSiteDAO locationSiteDAO, PurchaseOrderDAO purchaseOrderDAO, UserInventoryAccountDAO userInventoryAccountDAO) { this.jobCardDAO = jobCardDAO; this.cutPieceTypeDAO = cutPieceTypeDAO; this.jobCardItemDAO = jobCardItemDAO; @@ -44,6 +40,7 @@ public class JobCardService { this.itemDAO = itemDAO; this.locationSiteDAO = locationSiteDAO; this.purchaseOrderDAO = purchaseOrderDAO; + this.userInventoryAccountDAO = userInventoryAccountDAO; } /* @@ -66,8 +63,30 @@ public class JobCardService { /* * get cards * */ - public List getCards() { - return jobCardDAO.findAll(); + public List getCards( String id, + String code, + String status, + String inventoryStatus, + String customer, + String lotNumber, + String purchaseOrderId, + String locationSiteId, + String createdStartDate, + String createdEndDate, + Long limit) { + List jobCards = new ArrayList<>(); + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + if( limit == null ){ + limit = 100L; + } + if( StringUtils.isAnyNotNullOrEmpty( id, code, status, inventoryStatus, customer, lotNumber, purchaseOrderId, locationSiteId, createdStartDate, createdEndDate ) ){ + String query = JobCardQueryBuilder.buildQuery( id, code, authentication.getName(), status, inventoryStatus, customer, lotNumber, purchaseOrderId, locationSiteId, createdStartDate, createdEndDate, limit ); + System.out.println( query ); + jobCards = jobCardDAO.findByQuery( query ); + } else { + jobCards = jobCardDAO.findByUserAndLimit( authentication.getName(), limit ); + } + return jobCards; } /* @@ -130,6 +149,58 @@ public class JobCardService { * find card recursively * */ public JobCard findCardRecursively(long id) { + // get username + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); + JobCard jobCard = jobCardDAO.find(id); + // set po and site titles + jobCard.setPurchaseOrderTitle( purchaseOrderDAO.find( jobCard.getPurchaseOrderId() ).getCode() ); + jobCard.setLocationTitle( locationSiteDAO.find( jobCard.getLocationSiteId() ).getTitle() ); + + // fetch only those items which has account id assign to user + List accountIds = userInventoryAccountDAO.findByUsername( authentication.getName() ) + .stream() + .map( UserInventoryAccount::getAccountId ) + .collect( Collectors.toList() ); + + // get items has account ids and has actual production not filled + List items = jobCardItemDAO.findByJobCardAndAccountIdsAndIsReceived( id, 0L ,accountIds ); + if (items != null && !items.isEmpty()) { + // get job card ite ids + List jobCardItemIds = items.stream() + .map(JobCardItem::getId) + .collect(Collectors.toList()); + + // item Ids + List invItemIds = items.stream() + .map(JobCardItem::getItemId) + .collect(Collectors.toList()); + + Map> piecesMap = cutPieceDAO.findByJobCardItemIds( jobCardItemIds ) + .stream() + .collect(Collectors.groupingBy( CutPiece::getJobCardItemId )); + + Map itemMap = itemDAO.findByIds(invItemIds) + .stream() + .collect(Collectors.toMap(Item::getId, Function.identity())); + + for (JobCardItem item : items) { + item.setCutPieces(piecesMap.getOrDefault(item.getId(), new ArrayList<>())); + item.setTitle(itemMap.getOrDefault(item.getItemId(), new Item()).getTitle()); + } + } + jobCard.setItems(items); + return jobCard; + } + + + + + /* + * find card recursively + * */ + public JobCard findCardRecursivelyForView(long id) { + // get username + Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); JobCard jobCard = jobCardDAO.find(id); // set po and site titles jobCard.setPurchaseOrderTitle( purchaseOrderDAO.find( jobCard.getPurchaseOrderId() ).getCode() ); @@ -162,7 +233,6 @@ public class JobCardService { } jobCard.setItems(items); return jobCard; - } diff --git a/src/main/java/com/utopiaindustries/service/UserService.java b/src/main/java/com/utopiaindustries/service/UserService.java index 25ee323..62a001f 100644 --- a/src/main/java/com/utopiaindustries/service/UserService.java +++ b/src/main/java/com/utopiaindustries/service/UserService.java @@ -76,7 +76,7 @@ public class UserService { private void createUser( User user ){ User newUser = new User(); - newUser.setPassword( bCryptPasswordEncoder.encode( user.getPassword() ) ); + newUser.setPassword( user.getPassword() ); if( ! StringUtils.isNullOrEmpty( user.getNewPassword() )){ newUser.setPassword( bCryptPasswordEncoder.encode( user.getNewPassword() ) ); } diff --git a/src/main/resources/static/js/job-card-form.js b/src/main/resources/static/js/job-card-form.js index 2fc3d72..69ff2cf 100644 --- a/src/main/resources/static/js/job-card-form.js +++ b/src/main/resources/static/js/job-card-form.js @@ -1,19 +1,41 @@ (async function () { + Vue.prototype.$accounts = window.ctp.accounts; + Vue.prototype.$types = window.ctp.types; - Vue.component('item-table', { + Vue.component('job-card-items', { props: ['items'], methods: { removeItem: function (index) { + + } + }, + template: ` + + + + + + + `, + + + }); + + + Vue.component('job-card-item', { + props: ['index', 'item', 'items'], + methods: { + removeItem: function (e) { if (confirm('Do want to delete Item?')) { - if (this.items[index].id === 0) { - this.items.splice(index, 1); + if (this.items[this.index].id === 0) { + this.items.splice(this.index, 1); } else { // post request and reload page on success $.ajax({ - url: '/ctp/rest/job-cards?job-card-item-id=' + this.items[index].id, + url: '/ctp/rest/job-cards?job-card-item-id=' + this.items[this.index].id, method: 'POST', contentType: 'application/json', dataType: 'json', @@ -27,40 +49,6 @@ }); } } - } - }, - template: ` - - - - - - - - - - - - - - -
ItemItem Sku/TitleCut PanelsExpected ProductionAction
- `, - - - }); - - - Vue.component('item-rows', { - props: ['index', 'item'], - methods: { - removeItem: function (e) { - e.preventDefault(); - this.$emit('remove-item', this.index); }, addPieces: function (e) { e.preventDefault(); @@ -99,41 +87,83 @@ } }, template: ` - - +
- - - - - {{item.sku}} - - - - - - - - - - - - - + + +
+ + +
+
+ + {{item.sku}} +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + +
+
+
+
Cut Panels
+ + + + + + +
+
+ + +
` }); @@ -186,7 +216,14 @@ 'jobCardId': 0, 'itemId': 0, 'sku': '', - 'expectedProductionQuantity': 0.0, + 'expectedProduction': 0.0, + 'actualProduction' : 0.0, + 'length' : '', + 'width' : '', + 'gsm' : '', + 'wtPly' : '', + 'ply' : '', + 'accountId' : 0, cutPieces: [] } }, diff --git a/src/main/resources/static/js/receive-inventory.js b/src/main/resources/static/js/receive-inventory.js index abcb448..cc84bb0 100644 --- a/src/main/resources/static/js/receive-inventory.js +++ b/src/main/resources/static/js/receive-inventory.js @@ -1,14 +1,20 @@ ( async function(){ Vue.prototype.$types = window.ctp.types; + Vue.prototype.$accounts = window.ctp.accounts; Vue.component('item-rows', { props: ['index', 'item'], + methods : { + populateCuttingAccount : function (){ + return this.$accounts.find(account => account.id === this.item.accountId).title; + }, + }, template: ` - - + + - {{item.expectedProductionQuantity}} + {{item.expectedProduction}} + + + + + + {{ populateCuttingAccount() }} - ` }); - Vue.component('cut-piece', { + Vue.component ('cut-piece', { props: ['index', 'piece', 'pIndex'], methods: { removePiece: function (e) { @@ -46,34 +57,39 @@ }, template: `
- - + + +
- + v-bind:value="type.title">{{type.title}}
- {{piece.quantity}} +
` - }); Vue.component('job-card-details',{ props:[ 'jobCard' ], + methods : { + + }, template : ` - +
+ + diff --git a/src/main/resources/templates/_fragments.html b/src/main/resources/templates/_fragments.html index 889df44..cef98dc 100644 --- a/src/main/resources/templates/_fragments.html +++ b/src/main/resources/templates/_fragments.html @@ -28,32 +28,32 @@ - + - + - + + + + + @@ -40,6 +44,14 @@ - + + + + - + - + - + - - - - - - + + +
+ + +
+
+ + {{item.sku}} +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + +
+
+ + + + +
+
+
+
Cut Panels
+ + + + + + +
+
+ + + ` }); @@ -186,7 +216,14 @@ 'jobCardId': 0, 'itemId': 0, 'sku': '', - 'expectedProductionQuantity': 0.0, + 'expectedProduction': 0.0, + 'actualProduction' : 0.0, + 'length' : '', + 'width' : '', + 'gsm' : '', + 'wtPly' : '', + 'ply' : '', + 'accountId' : 0, cutPieces: [] } }, diff --git a/target/classes/static/js/receive-inventory.js b/target/classes/static/js/receive-inventory.js index abcb448..cc84bb0 100644 --- a/target/classes/static/js/receive-inventory.js +++ b/target/classes/static/js/receive-inventory.js @@ -1,14 +1,20 @@ ( async function(){ Vue.prototype.$types = window.ctp.types; + Vue.prototype.$accounts = window.ctp.accounts; Vue.component('item-rows', { props: ['index', 'item'], + methods : { + populateCuttingAccount : function (){ + return this.$accounts.find(account => account.id === this.item.accountId).title; + }, + }, template: ` + + - ` }); - Vue.component('cut-piece', { + Vue.component ('cut-piece', { props: ['index', 'piece', 'pIndex'], methods: { removePiece: function (e) { @@ -46,34 +57,39 @@ }, template: `
- - + + +
- + v-bind:value="type.title">{{type.title}}
- {{piece.quantity}} +
` - }); Vue.component('job-card-details',{ props:[ 'jobCard' ], + methods : { + + }, template : ` -
Item Item Sku/Title Cut Pieces Expected ProductionActual ProductionAccount
+ ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/src/main/resources/templates/cutting/receive-inventory.html b/src/main/resources/templates/cutting/receive-inventory.html index 2e45beb..2726917 100644 --- a/src/main/resources/templates/cutting/receive-inventory.html +++ b/src/main/resources/templates/cutting/receive-inventory.html @@ -12,7 +12,8 @@

Receive Inventory

+ id="receiveInvApp" + th:object="${wrapper}">
@@ -22,16 +23,16 @@ v-bind:required="true" >
-
- - -
+ + + + + + + + + +
@@ -47,7 +48,7 @@
{{jobCard.code}} {{jobCard.code}} {{jobCard.jobOrderId}} {{jobCard.status}} @@ -69,6 +70,7 @@ diff --git a/src/main/resources/templates/error/403.html b/src/main/resources/templates/error/403.html new file mode 100644 index 0000000..0a79365 --- /dev/null +++ b/src/main/resources/templates/error/403.html @@ -0,0 +1,23 @@ + + + + + +
+ +
+
+
+
+

403 - Access Denied

+

You are not authorized to view this page.

+

Please contact concerned department for granting you required rights.

+
+
+
+
+
+ +
+ + \ No newline at end of file diff --git a/src/main/resources/templates/finishing/inventory-accounts.html b/src/main/resources/templates/finishing/inventory-accounts.html index ca734b4..badacd3 100644 --- a/src/main/resources/templates/finishing/inventory-accounts.html +++ b/src/main/resources/templates/finishing/inventory-accounts.html @@ -44,7 +44,10 @@
+ ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/src/main/resources/templates/job-card-list.html b/src/main/resources/templates/job-card-list.html index b8e3f57..3be593d 100644 --- a/src/main/resources/templates/job-card-list.html +++ b/src/main/resources/templates/job-card-list.html @@ -23,6 +23,10 @@ Job Order Status Inventory StatusCustomerLot NumberPurchase Order IDLocation Site Added Date Added By Actions + + + + diff --git a/src/main/resources/templates/packaging/inventory-accounts.html b/src/main/resources/templates/packaging/inventory-accounts.html index 932d3c3..b5739df 100644 --- a/src/main/resources/templates/packaging/inventory-accounts.html +++ b/src/main/resources/templates/packaging/inventory-accounts.html @@ -44,7 +44,10 @@ + ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/src/main/resources/templates/quality-control/inventory-accounts.html b/src/main/resources/templates/quality-control/inventory-accounts.html index 932d3c3..b5739df 100644 --- a/src/main/resources/templates/quality-control/inventory-accounts.html +++ b/src/main/resources/templates/quality-control/inventory-accounts.html @@ -44,7 +44,10 @@ + ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/src/main/resources/templates/quality-control/qc-items-form.html b/src/main/resources/templates/quality-control/qc-items-form.html index a5ff8fb..e2f116e 100644 --- a/src/main/resources/templates/quality-control/qc-items-form.html +++ b/src/main/resources/templates/quality-control/qc-items-form.html @@ -21,7 +21,7 @@ >
- +
+ ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/src/main/resources/templates/stitching/stitching-item-form.html b/src/main/resources/templates/stitching/stitching-item-form.html index d525d23..31bfad4 100644 --- a/src/main/resources/templates/stitching/stitching-item-form.html +++ b/src/main/resources/templates/stitching/stitching-item-form.html @@ -38,18 +38,26 @@
Items
-
+
+ + + + diff --git a/target/classes/com/utopiaindustries/controller/CuttingController.class b/target/classes/com/utopiaindustries/controller/CuttingController.class index 4e9497d..ddd8e9e 100644 Binary files a/target/classes/com/utopiaindustries/controller/CuttingController.class and b/target/classes/com/utopiaindustries/controller/CuttingController.class differ diff --git a/target/classes/com/utopiaindustries/controller/FinishingController.class b/target/classes/com/utopiaindustries/controller/FinishingController.class index 9072a1c..42b2341 100644 Binary files a/target/classes/com/utopiaindustries/controller/FinishingController.class and b/target/classes/com/utopiaindustries/controller/FinishingController.class differ diff --git a/target/classes/com/utopiaindustries/controller/InventoryAccountController.class b/target/classes/com/utopiaindustries/controller/InventoryAccountController.class index 5e974ae..a5f6fa5 100644 Binary files a/target/classes/com/utopiaindustries/controller/InventoryAccountController.class and b/target/classes/com/utopiaindustries/controller/InventoryAccountController.class differ diff --git a/target/classes/com/utopiaindustries/controller/JobCardController.class b/target/classes/com/utopiaindustries/controller/JobCardController.class index cd1692c..1dee056 100644 Binary files a/target/classes/com/utopiaindustries/controller/JobCardController.class and b/target/classes/com/utopiaindustries/controller/JobCardController.class differ diff --git a/target/classes/com/utopiaindustries/controller/PackagingController.class b/target/classes/com/utopiaindustries/controller/PackagingController.class index 966d78a..4795a5e 100644 Binary files a/target/classes/com/utopiaindustries/controller/PackagingController.class and b/target/classes/com/utopiaindustries/controller/PackagingController.class differ diff --git a/target/classes/com/utopiaindustries/controller/QualityControlController.class b/target/classes/com/utopiaindustries/controller/QualityControlController.class index 2f738aa..6fc13ca 100644 Binary files a/target/classes/com/utopiaindustries/controller/QualityControlController.class and b/target/classes/com/utopiaindustries/controller/QualityControlController.class differ diff --git a/target/classes/com/utopiaindustries/controller/StitchingController.class b/target/classes/com/utopiaindustries/controller/StitchingController.class index 21591a2..e10bcac 100644 Binary files a/target/classes/com/utopiaindustries/controller/StitchingController.class and b/target/classes/com/utopiaindustries/controller/StitchingController.class differ diff --git a/target/classes/com/utopiaindustries/controller/UserController.class b/target/classes/com/utopiaindustries/controller/UserController.class index a7b0f5f..1282e21 100644 Binary files a/target/classes/com/utopiaindustries/controller/UserController.class and b/target/classes/com/utopiaindustries/controller/UserController.class differ diff --git a/target/classes/com/utopiaindustries/dao/ctp/InventoryAccountDAO.class b/target/classes/com/utopiaindustries/dao/ctp/InventoryAccountDAO.class index 4254d65..d293c04 100644 Binary files a/target/classes/com/utopiaindustries/dao/ctp/InventoryAccountDAO.class and b/target/classes/com/utopiaindustries/dao/ctp/InventoryAccountDAO.class differ diff --git a/target/classes/com/utopiaindustries/dao/ctp/JobCardDAO.class b/target/classes/com/utopiaindustries/dao/ctp/JobCardDAO.class index 1d143e5..1f30b81 100644 Binary files a/target/classes/com/utopiaindustries/dao/ctp/JobCardDAO.class and b/target/classes/com/utopiaindustries/dao/ctp/JobCardDAO.class differ diff --git a/target/classes/com/utopiaindustries/dao/ctp/JobCardItemDAO.class b/target/classes/com/utopiaindustries/dao/ctp/JobCardItemDAO.class index 641ed21..cfd240a 100644 Binary files a/target/classes/com/utopiaindustries/dao/ctp/JobCardItemDAO.class and b/target/classes/com/utopiaindustries/dao/ctp/JobCardItemDAO.class differ diff --git a/target/classes/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.class b/target/classes/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.class index 4b82418..bfbb445 100644 Binary files a/target/classes/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.class and b/target/classes/com/utopiaindustries/dao/ctp/JobCardItemRowMapper.class differ diff --git a/target/classes/com/utopiaindustries/model/Roles.class b/target/classes/com/utopiaindustries/model/Roles.class index 08dbffc..1a35ca5 100644 Binary files a/target/classes/com/utopiaindustries/model/Roles.class and b/target/classes/com/utopiaindustries/model/Roles.class differ diff --git a/target/classes/com/utopiaindustries/model/ctp/JobCardItem.class b/target/classes/com/utopiaindustries/model/ctp/JobCardItem.class index 9f1b5e8..b636927 100644 Binary files a/target/classes/com/utopiaindustries/model/ctp/JobCardItem.class and b/target/classes/com/utopiaindustries/model/ctp/JobCardItem.class differ diff --git a/target/classes/com/utopiaindustries/service/InventoryAccountService.class b/target/classes/com/utopiaindustries/service/InventoryAccountService.class index 345fc3a..ed4937c 100644 Binary files a/target/classes/com/utopiaindustries/service/InventoryAccountService.class and b/target/classes/com/utopiaindustries/service/InventoryAccountService.class differ diff --git a/target/classes/com/utopiaindustries/service/InventoryService.class b/target/classes/com/utopiaindustries/service/InventoryService.class index e964b4b..b72dab5 100644 Binary files a/target/classes/com/utopiaindustries/service/InventoryService.class and b/target/classes/com/utopiaindustries/service/InventoryService.class differ diff --git a/target/classes/com/utopiaindustries/service/JobCardService.class b/target/classes/com/utopiaindustries/service/JobCardService.class index e7bc2a9..eabcf1d 100644 Binary files a/target/classes/com/utopiaindustries/service/JobCardService.class and b/target/classes/com/utopiaindustries/service/JobCardService.class differ diff --git a/target/classes/com/utopiaindustries/service/UserService.class b/target/classes/com/utopiaindustries/service/UserService.class index 369b88a..0795307 100644 Binary files a/target/classes/com/utopiaindustries/service/UserService.class and b/target/classes/com/utopiaindustries/service/UserService.class differ diff --git a/target/classes/static/js/job-card-form.js b/target/classes/static/js/job-card-form.js index 2fc3d72..69ff2cf 100644 --- a/target/classes/static/js/job-card-form.js +++ b/target/classes/static/js/job-card-form.js @@ -1,19 +1,41 @@ (async function () { + Vue.prototype.$accounts = window.ctp.accounts; + Vue.prototype.$types = window.ctp.types; - Vue.component('item-table', { + Vue.component('job-card-items', { props: ['items'], methods: { removeItem: function (index) { + + } + }, + template: ` + + + + + + + `, + + + }); + + + Vue.component('job-card-item', { + props: ['index', 'item', 'items'], + methods: { + removeItem: function (e) { if (confirm('Do want to delete Item?')) { - if (this.items[index].id === 0) { - this.items.splice(index, 1); + if (this.items[this.index].id === 0) { + this.items.splice(this.index, 1); } else { // post request and reload page on success $.ajax({ - url: '/ctp/rest/job-cards?job-card-item-id=' + this.items[index].id, + url: '/ctp/rest/job-cards?job-card-item-id=' + this.items[this.index].id, method: 'POST', contentType: 'application/json', dataType: 'json', @@ -27,40 +49,6 @@ }); } } - } - }, - template: ` -
ID Item ID Sku Expected ProductionActual Production Current Production Production
+
+ + +
+
{{item.id}} @@ -63,8 +71,12 @@ {{item.sku}} - - {{item.expectedProductionQuantity}} + + {{item.expectedProduction}} + + + {{item.actualProduction}} @@ -75,8 +87,9 @@ type="number" v-bind:value="item.production" v-bind:min="0" - v-bind:max="item.expectedProductionQuantity - item.totalProduction" - required> + v-bind:max="item.actualProduction - item.totalProduction" + v-bind:readonly="!item.isSelected" + >
- - - - - - - - - - - - - -
ItemItem Sku/TitleCut PanelsExpected ProductionAction
- `, - - - }); - - - Vue.component('item-rows', { - props: ['index', 'item'], - methods: { - removeItem: function (e) { - e.preventDefault(); - this.$emit('remove-item', this.index); }, addPieces: function (e) { e.preventDefault(); @@ -99,41 +87,83 @@ } }, template: ` -
+
- - -
- {{item.sku}} - - - - - - - - -
- - + + - {{item.expectedProductionQuantity}} + {{item.expectedProduction}} + + + + {{ populateCuttingAccount() }}
+
+ + diff --git a/target/classes/templates/_fragments.html b/target/classes/templates/_fragments.html index 889df44..cef98dc 100644 --- a/target/classes/templates/_fragments.html +++ b/target/classes/templates/_fragments.html @@ -28,32 +28,32 @@ - + - + - + + + + + @@ -40,6 +44,14 @@ - + + + + - + - + - +
Item Item Sku/Title Cut Pieces Expected ProductionActual ProductionAccount
+ ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/target/classes/templates/cutting/receive-inventory.html b/target/classes/templates/cutting/receive-inventory.html index 2e45beb..2726917 100644 --- a/target/classes/templates/cutting/receive-inventory.html +++ b/target/classes/templates/cutting/receive-inventory.html @@ -12,7 +12,8 @@

Receive Inventory

+ id="receiveInvApp" + th:object="${wrapper}">
@@ -22,16 +23,16 @@ v-bind:required="true" >
-
- - -
+ + + + + + + + + +
@@ -47,7 +48,7 @@
{{jobCard.code}} {{jobCard.code}} {{jobCard.jobOrderId}} {{jobCard.status}} @@ -69,6 +70,7 @@ diff --git a/target/classes/templates/finishing/inventory-accounts.html b/target/classes/templates/finishing/inventory-accounts.html index ca734b4..badacd3 100644 --- a/target/classes/templates/finishing/inventory-accounts.html +++ b/target/classes/templates/finishing/inventory-accounts.html @@ -44,7 +44,10 @@ + ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/target/classes/templates/job-card-list.html b/target/classes/templates/job-card-list.html index b8e3f57..3be593d 100644 --- a/target/classes/templates/job-card-list.html +++ b/target/classes/templates/job-card-list.html @@ -23,6 +23,10 @@ Job Order Status Inventory StatusCustomerLot NumberPurchase Order IDLocation Site Added Date Added By Actions + + + + diff --git a/target/classes/templates/packaging/inventory-accounts.html b/target/classes/templates/packaging/inventory-accounts.html index 932d3c3..b5739df 100644 --- a/target/classes/templates/packaging/inventory-accounts.html +++ b/target/classes/templates/packaging/inventory-accounts.html @@ -44,7 +44,10 @@ + ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/target/classes/templates/quality-control/inventory-accounts.html b/target/classes/templates/quality-control/inventory-accounts.html index 932d3c3..b5739df 100644 --- a/target/classes/templates/quality-control/inventory-accounts.html +++ b/target/classes/templates/quality-control/inventory-accounts.html @@ -44,7 +44,10 @@ + ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/target/classes/templates/quality-control/qc-items-form.html b/target/classes/templates/quality-control/qc-items-form.html index a5ff8fb..e2f116e 100644 --- a/target/classes/templates/quality-control/qc-items-form.html +++ b/target/classes/templates/quality-control/qc-items-form.html @@ -21,7 +21,7 @@ >
- +
+ ACTIVE + INACTIVE + @@ -96,7 +99,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-transactions?account-id=${accountId}`, + url: `/ctp/inventory-transactions?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); @@ -119,7 +122,7 @@ else { $row.child(``).show(); $.ajax({ - url: `/ctp/cutting/inventory-summary?account-id=${accountId}`, + url: `/ctp/inventory-summary?account-id=${accountId}`, success: function( data ){ // show fetched page $row.child( data ).show(); diff --git a/target/classes/templates/stitching/stitching-item-form.html b/target/classes/templates/stitching/stitching-item-form.html index d525d23..31bfad4 100644 --- a/target/classes/templates/stitching/stitching-item-form.html +++ b/target/classes/templates/stitching/stitching-item-form.html @@ -38,18 +38,26 @@
Items
-
+
+ + + +
ID Item ID Sku Expected ProductionActual Production Current Production Production
+
+ + +
+
{{item.id}} @@ -63,8 +71,12 @@ {{item.sku}} - - {{item.expectedProductionQuantity}} + + {{item.expectedProduction}} + + + {{item.actualProduction}} @@ -75,8 +87,9 @@ type="number" v-bind:value="item.production" v-bind:min="0" - v-bind:max="item.expectedProductionQuantity - item.totalProduction" - required> + v-bind:max="item.actualProduction - item.totalProduction" + v-bind:readonly="!item.isSelected" + >