Advertisement
tko_pb

RequisitionActionHandler 13 September

Sep 12th, 2018
391
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.33 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.     private final String pendingRelease1="oez_pendingrelease1";
  37.     private final String pendingRelease2="oez_pendingrelease2";
  38.     private final String pendingRelease3="oez_pendingrelease3";
  39.     private final String pendingRelease4="oez_pendingrelease4";
  40.     private final String pendingRelease5="oez_pendingrelease5";
  41.  
  42.     @Override
  43.     public void doRouting(String adWindowId, String adTabId,
  44.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  45.         if (doc_status_to.equalsIgnoreCase(voidStatus))
  46.             throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
  47.  
  48.         for (String requisitionID : recordId){
  49.  
  50.             boolean isValidRequisition = validateRequistion(vars, requisitionID);
  51.             // jika product category == "INVESTASI" dan tidak memiliki attachment
  52.             if (!isValidRequisition)
  53.                 if( (doc_status_to.equalsIgnoreCase(pendingRelease1)) || (doc_status_to.equalsIgnoreCase(pendingRelease2)) || (doc_status_to.equalsIgnoreCase(pendingRelease3)) || (doc_status_to.equalsIgnoreCase(pendingRelease4)) || (doc_status_to.equalsIgnoreCase(pendingRelease5)) ){
  54.                     Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  55.                     //cek apakah doc_status adalah CL atau VO, jika ya exception
  56.                     if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  57.                             requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  58.                         throw new OBException("@ActionNotAllowedHere@");
  59.                     requisition.setDocumentAction(doc_status_to);
  60.                     OBDal.getInstance().save(requisition);
  61.                     OBDal.getInstance().flush();
  62.                 }
  63.                 else {
  64.                     throw new OBException("requisition is invalid, may be some requisition line has capital investment product but no attachment uploaded.");
  65.                 }
  66.             //jika product category != "INVESTASI" atau product category == "INVESTASI" dan memiliki attachment
  67.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  68.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  69.                 //cek apakah dari CL atau VO, jika ya, maka exception
  70.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  71.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  72.                     throw new OBException("@ActionNotAllowedHere@");
  73.  
  74.                 //ubdah dulu docstatus menjadi DR, baru di complete
  75.                 requisition.setDocumentStatus(draftStatus);
  76.                 requisition.setDocumentAction(doc_status_to);
  77.                 OBDal.getInstance().save(requisition);
  78.                 OBDal.getInstance().flush();
  79.  
  80.             }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)) ) {
  81.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  82.                 //cek apakah doc_status adalah CL atau VO, jika ya exception
  83.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  84.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  85.                     throw new OBException("@ActionNotAllowedHere@");
  86.                 requisition.setDocumentAction(doc_status_to);
  87.                 OBDal.getInstance().save(requisition);
  88.                 OBDal.getInstance().flush();   
  89.  
  90.             }else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  91.                 //cek apakah doc status adalah CO, jika tidak maka exception
  92.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  93.                 if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  94.                     throw new OBException("@ActionNotAllowedHere@");
  95.                 requisition.setDocumentAction(doc_status_to);
  96.                 OBDal.getInstance().save(requisition);
  97.                 OBDal.getInstance().flush();
  98.             }
  99.             doExecuteProcedureCall(requisitionID, processID);
  100.         }
  101.     }
  102.  
  103.     private boolean validateRequistion(VariablesSecureApp vars, String requisitionID) {
  104.         //jika memiliki lines yg inventory, dan memiliki attachment, maka dinyatakan valid
  105.         boolean isvalid=true;
  106.  
  107.         Requisition r = OBDal.getInstance().get(Requisition.class, requisitionID);
  108.         String investmentAssetGroupKey = Utility.getPreference(vars, "InvestmentAssetGroupKey", null);
  109.         if (StringUtils.isEmpty(investmentAssetGroupKey))
  110.             investmentAssetGroupKey="INVESTASI";
  111.         for (RequisitionLine rl : r.getProcurementRequisitionLineList()) {
  112.             boolean isInvestasi = rl.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase(investmentAssetGroupKey);
  113.  
  114.             if (isInvestasi)
  115.                 isvalid = isRequisitionLineHasAttachment(rl);
  116.             if (!isvalid)
  117.                 break;
  118.         }
  119.  
  120.         return isvalid;
  121.     }
  122.  
  123.     private boolean isRequisitionLineHasAttachment(RequisitionLine rl) {
  124.         String sqlquery = "select c_file_id from c_file"
  125.                 + " where ad_table_id= ?"
  126.                 + " and ad_record_id= ?";
  127.         ConnectionProvider conn = new DalConnectionProvider();
  128.         Connection connection;
  129.         boolean hasAttachment = false;
  130.         try {
  131.             connection = conn.getConnection();
  132.             PreparedStatement ps = connection.prepareStatement(sqlquery);
  133.             ps.setString(1, "800214"); //m_requisitionline
  134.             ps.setString(2, rl.getId());
  135.             ResultSet rs = ps.executeQuery();
  136.             while (rs.next())
  137.                 hasAttachment=true;
  138.  
  139.         } catch (NoConnectionAvailableException e) {
  140.             e.printStackTrace();
  141.             throw new OBException(e.getMessage());
  142.         } catch (SQLException e) {
  143.             e.printStackTrace();
  144.             throw new OBException("Attachment document is required for procurement of this product");
  145.         }
  146.         return hasAttachment;
  147.     }
  148.  
  149.     @Override
  150.     public String getCoDocumentNo(String recordID, Tab tab) {
  151.         // TODO sementara null dulu
  152.         return null;
  153.     }
  154.  
  155.     @Override
  156.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  157.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  158.                 document_status_to.equalsIgnoreCase(closedStatus))
  159.             return true;
  160.         else
  161.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  162.  
  163.     }
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement