Advertisement
aadddrr

ValNoProductConsignmentItemDuplicate

May 25th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.53 KB | None | 0 0
  1. package org.jleaf.erp.purch.bo.po;
  2.  
  3. import java.util.List;
  4.  
  5. import javax.persistence.Query;
  6.  
  7. import org.jleaf.core.AbstractBusinessFunction;
  8. import org.jleaf.core.BusinessFunction;
  9. import org.jleaf.core.CoreException;
  10. import org.jleaf.core.Dto;
  11. import org.jleaf.core.annotation.Info;
  12. import org.jleaf.core.annotation.InfoIn;
  13. import org.jleaf.core.dao.QueryBuilder;
  14. import org.jleaf.erp.master.dao.ProductDao;
  15. import org.jleaf.erp.master.entity.Product;
  16. import org.jleaf.erp.purch.PurchasingExceptionConstants;
  17. import org.jleaf.erp.purch.entity.PurchaseOrder;
  18. import org.jleaf.erp.purch.entity.PurchaseOrderItem;
  19. import org.slf4j.Logger;
  20. import org.slf4j.LoggerFactory;
  21. import org.springframework.beans.factory.annotation.Autowired;
  22. import org.springframework.stereotype.Service;
  23.  
  24. /**
  25.  * Perlu dilakukan validasi untuk produk konsinyasi dalam saat bersamaan tidak
  26.  * boleh ada produk yang duplikat
  27.  *
  28.  * 1. Cek ke tabel pu_po_item untuk PO yang masih DRAFT, product_id tersebut
  29.  * tidak boleh ada 2. Cek ke tabel pu_po_balance_item_consignment tidak boleh
  30.  * ada product_id itu yang status_item = 'R'
  31.  *
  32.  * @author Ali
  33.  *
  34.  */
  35. // @formatter:off
  36. @Service("valNoProductConsignmentItemDuplicate")
  37. @InfoIn(value = {
  38.         @Info(name = "currentPoId", description = "current po ID", type = Long.class),
  39.         @Info(name = "productId", description = "product ID to check", type = Long.class) })
  40. // @formatter:on
  41. public class ValNoProductConsignmentItemDuplicate extends
  42.         AbstractBusinessFunction implements BusinessFunction {
  43.  
  44.     private static final Logger log = LoggerFactory
  45.             .getLogger(ValNoProductConsignmentItemDuplicate.class);
  46.     @Autowired
  47.     private ProductDao productDao;
  48.  
  49.     public String getDescription() {
  50.         return "Validation no product consignment item duplicate";
  51.     }
  52.  
  53.     public Dto execute(Dto inputDto) throws Exception {
  54.         Long currentPoId = inputDto.getLong("currentPoId");
  55.         Long productId = inputDto.getLong("productId");
  56.        
  57.         log.info(">>>>>>>>>> log current PO Id >>>>>>>>>>>>>>" + currentPoId);
  58.         log.info(">>>>>>>>>> log product Id >>>>>>>>>>>>>>" + productId);
  59.        
  60.  
  61.         // Cek ke tabel pu_po_item untuk PO yang masih DRAFT, product_id
  62.         // tersebut tidak boleh ada
  63.         QueryBuilder builder = new QueryBuilder();
  64.         builder.add("SELECT A.po_item_id, A.po_id, B.doc_no, C.product_code FROM ");
  65.         builder.add(PurchaseOrderItem.TABLE_NAME).add(" A");
  66.         builder.add(" INNER JOIN ");
  67.         builder.add(PurchaseOrder.TABLE_NAME).add(" B ");
  68.         builder.add(" ON A.po_id=B.po_id ");
  69.         builder.add(" INNER JOIN ");
  70.         builder.add(Product.TABLE_NAME).add(" C ");
  71.         builder.add(" ON C.product_id=A.product_id ");
  72.         builder.add(" WHERE B.status_doc IN ('D','I') AND C.product_id = "
  73.                 + productId);
  74.         builder.addIfNotEmpty(currentPoId, " AND A.po_id <> " + currentPoId);
  75.  
  76.         Query query = productDao.createNativeQuery(builder.toString());
  77.         List<Object[]> list = query.getResultList();
  78.         int countDuplicate = list.size();
  79.  
  80.         log.info(">>>>>>>>>> isi buildernya >>>>>>>>>>>>>>" + builder.toString());
  81.        
  82.         if (countDuplicate > 0) {
  83.             String productCode = String.valueOf(list.get(0)[3]);
  84.             String docNo = String.valueOf(list.get(0)[2]);
  85.             throw new CoreException(
  86.                     PurchasingExceptionConstants.PRODUCT_CURRENTLY_USED_IN_ANOTHER_TRANSACTION,
  87.                     productCode,
  88.                     docNo);
  89.         }
  90.  
  91.         // Cek ke tabel pu_po_balance_item_consignment tidak boleh ada
  92.         // product_id itu yang status_item <> 'F'
  93.         builder = new QueryBuilder();
  94.         builder.add("SELECT A.po_item_id, A.po_id, B.doc_no, D.product_code FROM ");
  95.         builder.add(PurchaseOrderItem.TABLE_NAME).add(" A");
  96.         builder.add(" INNER JOIN ");
  97.         builder.add(PurchaseOrder.TABLE_NAME).add(" B ");
  98.         builder.add(" ON A.po_id=B.po_id ");
  99.         builder.add(" INNER JOIN ");
  100.         builder.add(" pu_po_balance_item_consignment C");
  101.         builder.add(" ON A.po_item_id=C.po_item_id ");
  102.         builder.add(" INNER JOIN ");
  103.         builder.add(Product.TABLE_NAME).add(" D ");
  104.         builder.add(" ON D.product_id=A.product_id ");
  105.         builder.add(" WHERE C.status_item <> 'F' AND D.product_id = " + productId);
  106.  
  107.         query = productDao.createNativeQuery(builder.toString());
  108.         list = query.getResultList();
  109.         countDuplicate = list.size();
  110.  
  111.         log.info(">>>>>>>>>> isi buildernya yang ke 2 >>>>>>>>>>>>>>" + builder.toString());
  112.        
  113.         if (countDuplicate > 0) {
  114.             String productCode = String.valueOf(list.get(0)[3]);
  115.             String docNo = String.valueOf(list.get(0)[2]);
  116.             throw new CoreException(
  117.                     PurchasingExceptionConstants.PRODUCT_CURRENTLY_USED_IN_ANOTHER_TRANSACTION,
  118.                     productCode,
  119.                     docNo);
  120.         }
  121.  
  122.         return null;
  123.     }
  124.  
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement