Advertisement
tko_pb

RequisitionActionHandler 13 September Bagian 2

Sep 12th, 2018
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 6.27 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.model.Entity;
  12. import org.openbravo.base.secureApp.VariablesSecureApp;
  13. import org.openbravo.dal.service.OBDal;
  14. import org.openbravo.database.ConnectionProvider;
  15. import org.openbravo.erpCommon.utility.Utility;
  16. import org.openbravo.exception.NoConnectionAvailableException;
  17. import org.openbravo.model.ad.ui.Tab;
  18. import org.openbravo.model.procurement.Requisition;
  19. import org.openbravo.model.procurement.RequisitionLine;
  20. import org.openbravo.service.db.DalConnectionProvider;
  21. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  22.  
  23. public class RequisitionActionHandler extends DocumentRoutingHandlerAction {
  24.     private final String reactiveStatus="RE";
  25.     private final String completeStatus="CO";
  26.     private final String draftStatus="DR";
  27.     private final String closedStatus="CL";
  28.     private final String voidStatus="VO";
  29.     private final String processID="1004400003";
  30.     private final String waitingRelease1="oez_waitingrelease1";
  31.     private final String waitingRelease2="oez_waitingrelease2";
  32.     private final String waitingRelease3="oez_waitingrelease3";
  33.     private final String waitingRelease4="oez_waitingrelease4";
  34.     private final String waitingRelease5="oez_waitingrelease5";
  35.    
  36.     @Override
  37.     public void doRouting(String adWindowId, String adTabId,
  38.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  39.         if (doc_status_to.equalsIgnoreCase(voidStatus))
  40.             throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
  41.  
  42.         for (String requisitionID : recordId){
  43.                        
  44.             // jika product category == "INVESTASI" dan tidak memiliki attachment
  45.             boolean isValidRequisition = validateRequistion(vars, requisitionID);
  46.             if (!isValidRequisition)  
  47.                 throw new OBException("requisition is invalid, may be some requisition line has capital investment product but no attachment uploaded.");
  48.            
  49.             //jika product category != "INVESTASI" atau product category == "INVESTASI" dan memiliki attachment
  50.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  51.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  52.                 //cek apakah dari CL atau VO, jika ya, maka exception
  53.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  54.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  55.                     throw new OBException("@ActionNotAllowedHere@");
  56.  
  57.                 //ubdah dulu docstatus menjadi DR, baru di complete
  58.                 requisition.setDocumentStatus(draftStatus);
  59.                 requisition.setDocumentAction(doc_status_to);
  60.                 OBDal.getInstance().save(requisition);
  61.                 OBDal.getInstance().flush();
  62.  
  63.             }else if((doc_status_to.equalsIgnoreCase(waitingRelease1)) || (doc_status_to.equalsIgnoreCase(waitingRelease2)) || (doc_status_to.equalsIgnoreCase(waitingRelease3)) || (doc_status_to.equalsIgnoreCase(waitingRelease4)) || (doc_status_to.equalsIgnoreCase(waitingRelease5)) ) {
  64.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  65.                 //cek apakah doc_status adalah CL atau VO, jika ya exception
  66.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  67.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  68.                     throw new OBException("@ActionNotAllowedHere@");
  69.                 requisition.setDocumentAction(doc_status_to);
  70.                 OBDal.getInstance().save(requisition);
  71.                 OBDal.getInstance().flush();   
  72.  
  73.             }else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  74.                 //cek apakah doc status adalah CO, jika tidak maka exception
  75.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  76.                 if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  77.                     throw new OBException("@ActionNotAllowedHere@");
  78.                 requisition.setDocumentAction(doc_status_to);
  79.                 OBDal.getInstance().save(requisition);
  80.                 OBDal.getInstance().flush();
  81.             }
  82.             doExecuteProcedureCall(requisitionID, processID);
  83.         }
  84.     }
  85.  
  86.     private boolean validateRequistion(VariablesSecureApp vars, String requisitionID) {
  87.         //jika memiliki lines yg inventory, dan memiliki attachment, maka dinyatakan valid
  88.         boolean isvalid=true;
  89.  
  90.         Requisition r = OBDal.getInstance().get(Requisition.class, requisitionID);
  91.         String investmentAssetGroupKey = Utility.getPreference(vars, "InvestmentAssetGroupKey", null);
  92.         if (StringUtils.isEmpty(investmentAssetGroupKey))
  93.             investmentAssetGroupKey="INVESTASI";
  94.         for (RequisitionLine rl : r.getProcurementRequisitionLineList()) {
  95.             boolean isInvestasi = rl.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase(investmentAssetGroupKey);
  96.  
  97.             if (isInvestasi)
  98.                 isvalid = isRequisitionLineHasAttachment(rl);
  99.             if (!isvalid)
  100.                 break;
  101.         }
  102.  
  103.         return isvalid;
  104.     }
  105.  
  106.     private boolean isRequisitionLineHasAttachment(RequisitionLine rl) {
  107.         String sqlquery = "select c_file_id from c_file"
  108.                 + " where ad_table_id= ?"
  109.                 + " and ad_record_id= ?";
  110.         ConnectionProvider conn = new DalConnectionProvider();
  111.         Connection connection;
  112.         boolean hasAttachment = false;
  113.         try {
  114.             connection = conn.getConnection();
  115.             PreparedStatement ps = connection.prepareStatement(sqlquery);
  116.             ps.setString(1, "800214"); //m_requisitionline
  117.             ps.setString(2, rl.getId());
  118.             ResultSet rs = ps.executeQuery();
  119.             while (rs.next())
  120.                 hasAttachment=true;
  121.  
  122.         } catch (NoConnectionAvailableException e) {
  123.             e.printStackTrace();
  124.             throw new OBException(e.getMessage());
  125.         } catch (SQLException e) {
  126.             e.printStackTrace();
  127.             throw new OBException("Attachment document is required for procurement of this product");
  128.         }
  129.         return hasAttachment;
  130.     }
  131.  
  132.     @Override
  133.     public String getCoDocumentNo(String recordID, Tab tab) {
  134.         // TODO sementara null dulu
  135.         return null;
  136.     }
  137.  
  138.     @Override
  139.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  140.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  141.                 document_status_to.equalsIgnoreCase(closedStatus))
  142.             return true;
  143.         else
  144.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  145.  
  146.     }
  147.  
  148. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement