tko_pb

RequisitionActionHandlerForWaitingRelease

Sep 13th, 2018
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.54 KB | None | 0 0
  1. package org.wirabumi.gen.oez.porting;
  2.  
  3. import java.sql.Connection;
  4. import java.sql.PreparedStatement;
  5. import java.sql.ResultSet;
  6. import java.sql.SQLException;
  7. import java.util.List;
  8.  
  9. import org.apache.commons.lang.StringUtils;
  10. import org.openbravo.base.exception.OBException;
  11. import org.openbravo.base.secureApp.VariablesSecureApp;
  12. import org.openbravo.dal.service.OBDal;
  13. import org.openbravo.database.ConnectionProvider;
  14. import org.openbravo.erpCommon.utility.Utility;
  15. import org.openbravo.exception.NoConnectionAvailableException;
  16. import org.openbravo.model.ad.ui.Tab;
  17. import org.openbravo.model.procurement.Requisition;
  18. import org.openbravo.model.procurement.RequisitionLine;
  19. import org.openbravo.service.db.DalConnectionProvider;
  20. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  21.  
  22. public class RequisitionActionHandlerForWaitingRelease extends DocumentRoutingHandlerAction {
  23.    
  24.     @Override
  25.     public void doRouting(String adWindowId, String adTabId, String doc_status_to, VariablesSecureApp vars,
  26.             List<String> recordId) {
  27.         // TODO Auto-generated method stub
  28.  
  29.         for (String requisitionID : recordId){
  30.             if (!doc_status_to.toLowerCase().contains("oez_waitingrelease")) {
  31.                 throw new OBException("@ActionNotAllowedHere@");
  32.  
  33.             }          
  34.             // validation investasi dan punya attachment
  35.             boolean isValidRequisition = validateRequistion(vars, requisitionID);
  36.             if (!isValidRequisition)  
  37.                 throw new OBException("requisition is invalid, may be some requisition line has capital investment product but no attachment uploaded.");
  38.  
  39.             Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  40.             requisition.setDocumentAction(doc_status_to);
  41.             OBDal.getInstance().save(requisition);
  42.             OBDal.getInstance().flush();   
  43.         }
  44.     }
  45.  
  46.     private boolean validateRequistion(VariablesSecureApp vars, String requisitionID) {
  47.         //jika memiliki lines yg inventory, dan memiliki attachment, maka dinyatakan valid
  48.         boolean isvalid=true;
  49.  
  50.         Requisition r = OBDal.getInstance().get(Requisition.class, requisitionID);
  51.         String investmentAssetGroupKey = Utility.getPreference(vars, "InvestmentAssetGroupKey", null);
  52.         if (StringUtils.isEmpty(investmentAssetGroupKey))
  53.             investmentAssetGroupKey="INVESTASI";
  54.         for (RequisitionLine rl : r.getProcurementRequisitionLineList()) {
  55.             boolean isInvestasi = rl.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase(investmentAssetGroupKey);
  56.  
  57.             if (isInvestasi)
  58.                 isvalid = isRequisitionLineHasAttachment(rl);
  59.             if (!isvalid)
  60.                 break;
  61.         }
  62.  
  63.         return isvalid;
  64.     }
  65.  
  66.     private boolean isRequisitionLineHasAttachment(RequisitionLine rl) {
  67.         String sqlquery = "select c_file_id from c_file"
  68.                 + " where ad_table_id= ?"
  69.                 + " and ad_record_id= ?";
  70.         ConnectionProvider conn = new DalConnectionProvider();
  71.         Connection connection;
  72.         boolean hasAttachment = false;
  73.         try {
  74.             connection = conn.getConnection();
  75.             PreparedStatement ps = connection.prepareStatement(sqlquery);
  76.             ps.setString(1, "800214"); //m_requisitionline
  77.             ps.setString(2, rl.getId());
  78.             ResultSet rs = ps.executeQuery();
  79.             while (rs.next())
  80.                 hasAttachment=true;
  81.  
  82.         } catch (NoConnectionAvailableException e) {
  83.             e.printStackTrace();
  84.             throw new OBException(e.getMessage());
  85.         } catch (SQLException e) {
  86.             e.printStackTrace();
  87.             throw new OBException("Attachment document is required for procurement of this product");
  88.         }
  89.         return hasAttachment;
  90.     }
  91.  
  92.     @Override
  93.     public String getCoDocumentNo(String recordID, Tab tab) {
  94.         // TODO sementara null dulu
  95.         return null;
  96.     }
  97. }
Add Comment
Please, Sign In to add comment