Advertisement
aadddrr

ValProductCanOnlyInOnePoConsignmentManual

May 27th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 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.GeneralConstants;
  12. import org.jleaf.core.annotation.ErrorList;
  13. import org.jleaf.core.annotation.Info;
  14. import org.jleaf.core.annotation.InfoIn;
  15. import org.jleaf.core.dao.QueryBuilder;
  16. import org.jleaf.erp.purch.entity.PurchaseOrder;
  17. import org.jleaf.erp.purch.entity.PurchaseOrderExt;
  18. import org.jleaf.erp.purch.entity.PurchaseOrderItem;
  19. import org.jleaf.erp.purch.entity.PurchaseOrderBalanceItem;
  20. import org.jleaf.erp.purch.PurchasingConstants;
  21. import org.jleaf.erp.purch.PurchasingExceptionConstantsForCland;
  22. import org.jleaf.erp.purch.dao.PurchaseOrderBalanceItemDao;
  23. import org.slf4j.Logger;
  24. import org.slf4j.LoggerFactory;
  25. import org.springframework.beans.factory.annotation.Autowired;
  26. import org.springframework.stereotype.Service;
  27.  
  28. /**
  29.  * Memperbaiki pesan exception
  30.  * modified by Adrian
  31.  * May 28, 2018
  32.  */
  33.  
  34. // @formatter:off
  35. @Service
  36. @InfoIn(value = {
  37.         @Info(name = "productId", description = "product ID to check", type = Long.class)
  38. })
  39.  
  40. @ErrorList(errorKeys = {
  41.         PurchasingExceptionConstantsForCland.THERE_SOME_PRODUCT_ALREADY_USE_ANOTHER_TRANSACTION
  42. })
  43.  
  44. // @formatter:on
  45. public class ValProductCanOnlyInOnePoConsignmentManual extends AbstractBusinessFunction implements BusinessFunction {
  46.  
  47.     private static final Logger log = LoggerFactory.getLogger(ValProductCanOnlyInOnePoConsignmentManual.class);
  48.     @Autowired
  49.     private PurchaseOrderBalanceItemDao purchaseOrderBalanceItemDao;
  50.  
  51.     public String getDescription() {
  52.         return "Validasi Produk yang ada di PO konsinyasi manual untuk produk tersebut jika status item R / I";
  53.     }
  54.  
  55.     @SuppressWarnings("unchecked")
  56.     public Dto execute(Dto inputDto) throws Exception {
  57.  
  58.         log.debug(" iya coy sudah masuk sini product nya " + inputDto);
  59.        
  60.         List<Object[]> result = null;
  61.        
  62.         QueryBuilder builder = new QueryBuilder();
  63.         builder.add(" SELECT D.doc_no, f_get_product_code(B.product_id) AS product_code ")
  64.         .add(" FROM ").add(PurchaseOrderBalanceItem.TABLE_NAME).add(" A ")
  65.         .add(" INNER JOIN ").add(PurchaseOrderItem.TABLE_NAME).add(" B ON A.po_item_id = B.po_item_id ")
  66.         .add(" INNER JOIN ").add(PurchaseOrderExt.TABLE_NAME).add(" C ON B.po_id = C.po_id ")
  67.         .add(" INNER JOIN ").add(PurchaseOrder.TABLE_NAME).add(" D ON C.po_id = D.po_id ")
  68.         .add(" WHERE A.status_item IN (:RELEASED,:INPROGRESS) AND B.product_id = :productId ")
  69.         .add(" AND C.flg_buy_consignment = :NO ")
  70.         .add(" AND C.flg_konsinyasi_manual = :YES ");
  71.        
  72.         Query query = purchaseOrderBalanceItemDao.createNativeQuery(builder.toString());
  73.         query.setParameter("productId", inputDto.getLong("productId"));
  74.         query.setParameter("RELEASED", PurchasingConstants.RELEASED_TRANSACTION);
  75.         query.setParameter("INPROGRESS", PurchasingConstants.IN_PROGRESS_TRANSACTION);
  76.         query.setParameter("NO", GeneralConstants.NO);
  77.         query.setParameter("YES", GeneralConstants.YES);
  78.  
  79.         result = query.getResultList();
  80.  
  81.         List<Object[]> list = result;
  82.    
  83.         if(list.size() > 0) {
  84.             String productCode = String.valueOf(list.get(0)[1]);
  85.             String docNo = String.valueOf(list.get(0)[0]);
  86.             throw new CoreException(
  87.                     PurchasingExceptionConstantsForCland.THERE_SOME_PRODUCT_ALREADY_USE_ANOTHER_TRANSACTION,
  88.                     productCode,
  89.                     docNo);
  90.         }
  91.        
  92.         return new Dto();
  93.        
  94.     }
  95.    
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement