Advertisement
tko_pb

RequisitionActionHandler 7

Jul 6th, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.34 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.ArrayList;
  8. import java.util.List;
  9.  
  10. import org.hibernate.criterion.Restrictions;
  11. import org.openbravo.base.exception.OBException;
  12. import org.openbravo.base.model.Entity;
  13. import org.openbravo.base.secureApp.VariablesSecureApp;
  14. import org.openbravo.base.structure.BaseOBObject;
  15. import org.openbravo.dal.service.OBCriteria;
  16. import org.openbravo.dal.service.OBDal;
  17. import org.openbravo.database.ConnectionProvider;
  18. import org.openbravo.erpCommon.utility.OBError;
  19. import org.openbravo.exception.NoConnectionAvailableException;
  20. import org.openbravo.model.ad.datamodel.Table;
  21. import org.openbravo.model.ad.ui.Tab;
  22. import org.openbravo.model.ad.utility.Attachment;
  23. import org.openbravo.model.common.plm.ProductCategory;
  24. import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
  25. import org.openbravo.model.procurement.Requisition;
  26. import org.openbravo.model.procurement.RequisitionLine;
  27. import org.openbravo.service.db.DalConnectionProvider;
  28. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  29.  
  30. import com.sun.corba.se.spi.orbutil.fsm.Guard.Result;
  31.  
  32. public class RequisitionActionHandler extends DocumentRoutingHandlerAction {
  33.     private final String reactiveStatus="RE";
  34.     private final String completeStatus="CO";
  35.     private final String draftStatus="DR";
  36.     private final String closedStatus="CL";
  37.     private final String voidStatus="VO";
  38.     private final String processID="1004400003";
  39.  
  40.     @Override
  41.     public void doRouting(String adWindowId, String adTabId,
  42.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  43.         if (doc_status_to.equalsIgnoreCase(voidStatus))
  44.             throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
  45.  
  46.         for (String requisitionID : recordId){
  47.             //boolean isValidRequistionLine = isRequisitionLineHasAttachment(requisitionID);
  48.             boolean isValidRequistionLine = validateRequisitionLine(requisitionID);
  49.             if (!isValidRequistionLine) {
  50.                 throw new OBException("Attachment document is required for procurement of this product");
  51.             }
  52.  
  53.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  54.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  55.  
  56.                 //cek apakah dari CL atau VO, jika ya, maka exception
  57.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  58.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  59.                     throw new OBException("@ActionNotAllowedHere@");
  60.  
  61.                 //ubdah dulu docstatus menjadi DR, baru di complete
  62.                 requisition.setDocumentStatus(draftStatus);
  63.                 requisition.setDocumentAction(doc_status_to);
  64.                 OBDal.getInstance().save(requisition);
  65.                 OBDal.getInstance().flush();
  66.  
  67.             } else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  68.                 //cek apakah doc status adalah CO, jika tidak maka exception
  69.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  70.                 if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  71.                     throw new OBException("@ActionNotAllowedHere@");
  72.                 requisition.setDocumentAction(doc_status_to);
  73.                 OBDal.getInstance().save(requisition);
  74.                 OBDal.getInstance().flush();
  75.             }
  76.             doExecuteProcedureCall(requisitionID, processID);
  77.         }
  78.     }
  79.  
  80.     //public boolean isRequisitionLineHasAttachment (String requisitionID) {
  81.     public boolean validateRequisitionLine (String requisitionID) {
  82.         boolean isValid = false;
  83.         Requisition requi = OBDal.getInstance().get(Requisition.class, requisitionID);
  84.         for (RequisitionLine re : requi.getProcurementRequisitionLineList()) {
  85.             boolean isInvestasi = re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true;
  86.             if (isInvestasi)
  87.                 isValid = isRequisitionLineHasAttachment(re);
  88.         }
  89.         return isValid;
  90.     }
  91.  
  92.     public Boolean isRequisitionLineHasAttachment(RequisitionLine re) {
  93.         boolean isValid = false;
  94.         String sqlquery = "select c_file_id from c_file"
  95.                 + " where ad_table_id= ? "
  96.                 + " and ad_record_id= ? " ;
  97.         ConnectionProvider conn = new DalConnectionProvider();
  98.         Connection connection;
  99.         boolean hasAttachment = false;
  100.         try {
  101.             connection = conn.getConnection();
  102.             PreparedStatement ps = connection.prepareStatement(sqlquery);
  103.             ps.setString(1, "800214");
  104.             ps.setString(2, re.getId());
  105.             ResultSet rs = ps.executeQuery();
  106.             while (rs.next())
  107.                 hasAttachment=true;
  108.         } catch (NoConnectionAvailableException e) {
  109.             e.printStackTrace();
  110.             throw new OBException(e.getMessage());
  111.         } catch (SQLException e) {
  112.             e.printStackTrace();
  113.             throw new OBException(e.getMessage());
  114.         }
  115.         if(!hasAttachment) // INVESTASI tidak punya attachment
  116.             isValid = false;
  117.         else if (hasAttachment) //INVESTASI punya attachment
  118.             isValid = true;
  119.         return isValid;
  120.     }
  121.  
  122.     @Override
  123.     public String getCoDocumentNo(String recordID, Tab tab) {
  124.         // TODO sementara null dulu
  125.         return null;
  126.     }
  127.  
  128.     @Override
  129.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  130.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  131.                 document_status_to.equalsIgnoreCase(closedStatus))
  132.             return true;
  133.         else
  134.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  135.  
  136.     }
  137.  
  138. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement