Advertisement
tko_pb

GoodsMovementActionHandler 3 oktober

Oct 2nd, 2018
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.46 KB | None | 0 0
  1. package org.wirabumi.gen.oez.porting;
  2.  
  3. import java.math.BigDecimal;
  4. import java.sql.SQLException;
  5. import java.util.List;
  6.  
  7. import org.hibernate.criterion.Restrictions;
  8. import org.openbravo.base.exception.OBException;
  9. import org.openbravo.base.secureApp.VariablesSecureApp;
  10. import org.openbravo.dal.service.OBCriteria;
  11. import org.openbravo.dal.service.OBDal;
  12. import org.openbravo.erpCommon.utility.OBError;
  13. import org.openbravo.model.ad.ui.Tab;
  14. import org.openbravo.model.ad.utility.Tree;
  15. import org.openbravo.model.ad.utility.TreeNode;
  16. import org.openbravo.model.common.enterprise.Locator;
  17. import org.openbravo.model.common.plm.Product;
  18. import org.openbravo.model.common.uom.UOM;
  19. import org.openbravo.model.materialmgmt.onhandquantity.ProductStockView;
  20. import org.openbravo.model.materialmgmt.onhandquantity.StorageDetail;
  21. import org.openbravo.model.materialmgmt.transaction.InternalMovement;
  22. import org.openbravo.model.materialmgmt.transaction.InternalMovementLine;
  23. import org.openbravo.model.materialmgmt.transaction.MaterialTransaction;
  24. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  25.  
  26. public class GoodsMovementActionHandler extends DocumentRoutingHandlerAction {
  27.     private final String reactiveStatus="RE";
  28.     private final String inoutProcessID="122";
  29.     private final String completeStatus="CO";
  30.     private final String closedStatus="CL";
  31.     private final String voidStatus="VO";
  32.     private final String draftStatus="DR";
  33.  
  34.     @Override
  35.     public void doRouting(String adWindowId, String adTabId,
  36.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  37.         if (doc_status_to.equalsIgnoreCase(reactiveStatus))
  38.             throw new OBException("@ActionNotAllowedHere@"); //shipment inout tidak boleh di reactive
  39.  
  40.         for (String goodsMovementID : recordId){
  41.  
  42.             InternalMovement goodMovId = OBDal.getInstance().get(InternalMovement.class, goodsMovementID);
  43.             String docstatus = goodMovId.getOezDocstatus();
  44.             String docaction = goodMovId.getOezDocaction();
  45.             if(doc_status_to.equalsIgnoreCase(completeStatus)) {
  46.                 for (InternalMovementLine goodMovLineId : goodMovId.getMaterialMgmtInternalMovementLineList())
  47.                 {
  48.                     Locator bin = goodMovLineId.getStorageBin();
  49.                     Product productId = goodMovLineId.getProduct(); // getProduct nya
  50.                     BigDecimal quantityOnHand = BigDecimal.valueOf(0);
  51.  
  52.                     for (StorageDetail sd : bin.getMaterialMgmtStorageDetailList()) {
  53.                         if (sd.getProduct().equals(productId))
  54.                             quantityOnHand=sd.getQuantityOnHand();
  55.                     }
  56.  
  57.                     String productName = goodMovLineId.getProduct().getName();
  58.                     int qntyMovementLines = goodMovLineId.getMovementQuantity().intValue();
  59.                     String uom = goodMovLineId.getUOM().getName();
  60.                     String originalWarehouse = goodMovLineId.getStorageBin().getSearchKey();
  61.                     if(goodMovLineId.getMovementQuantity().compareTo(quantityOnHand) > 0 )
  62.                     {              
  63.                         String string =  String.format("Insufficient stock for Product %s with %2d UOM %s and Storage Bin %s",  productName, qntyMovementLines, uom, originalWarehouse);
  64.                         throw new OBException(string);
  65.                     }
  66.                 }
  67.             }
  68.            
  69.             // cek apakah dari CL atau VO. jika ya maka exception
  70.             if(goodMovId.getOezDocstatus().equalsIgnoreCase(closedStatus) ||
  71.                     goodMovId.getOezDocstatus().equalsIgnoreCase(voidStatus))
  72.                 throw new OBException("@ActionNotAllowedHere@");
  73.  
  74.             // ubah oezdocstatus menjadi DR, baru di complete
  75.             goodMovId.setOezDocstatus(draftStatus);
  76.             goodMovId.setOezDocaction(doc_status_to);
  77.             OBDal.getInstance().save(goodMovId);
  78.             try {
  79.                 OBDal.getInstance().getConnection().commit();
  80.             } catch (SQLException e) {
  81.                 e.printStackTrace();
  82.                 throw new OBException(e.getMessage());
  83.             }
  84.  
  85.             try {
  86.                 OBError oberror = doExecuteProcedureCall(goodsMovementID, inoutProcessID);
  87.                 if (oberror.getType().equals("Error"))
  88.                     throw new OBException(oberror.getMessage());                   
  89.             } catch (Exception e) {
  90.                 // terjadi exception kembalikan ke doc_status
  91.                 goodMovId.setOezDocstatus(docstatus);
  92.                 goodMovId.setOezDocaction(docaction);
  93.                 OBDal.getInstance().save(goodMovId);
  94.                 try {
  95.                     OBDal.getInstance().getConnection().commit();
  96.                 } catch (SQLException e2) {
  97.                     e.printStackTrace();
  98.                     throw new OBException(e.getMessage());
  99.                 }
  100.                
  101.                 //throw chain exception
  102.                 e.printStackTrace();
  103.                 throw new OBException(e.getMessage());
  104.             }
  105.         }
  106.  
  107.     }
  108.  
  109.     @Override
  110.     public String getCoDocumentNo(String recordID, Tab tab) {
  111.         // TODO semengtara null dulu
  112.         return null;
  113.     }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement