Advertisement
tko_pb

RequisitionActionHandler 6

Jul 5th, 2018
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.10 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.     /*tiko [langkah-langkah]
  41.  
  42.       1. jika tabel null maka
  43.       2. seleksi list  untuk ambil id requisition,  dan line dari requisition yang sedang approval dengan record id
  44.       3. seleksi apak line memiliki product category search key "INVESTASI" atau tidak? * done
  45.       4. jika bernilai investasi dan tidak memiliki attachments maka OBException * done
  46.      */
  47.  
  48.     @Override
  49.     public void doRouting(String adWindowId, String adTabId,
  50.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  51.         if (doc_status_to.equalsIgnoreCase(voidStatus))
  52.             throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
  53.  
  54.         for (String requisitionID : recordId){
  55.  
  56.             Requisition requi = OBDal.getInstance().get(Requisition.class, requisitionID);
  57.             List <RequisitionLine> requiL = requi.getProcurementRequisitionLineList();
  58.  
  59.             for (RequisitionLine re : requiL) {
  60.                 if (re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true) {
  61.                     String sqlquery = "select c_file_id from c_file"
  62.                             + "where ad_table_id= ?"
  63.                             + "and ad_record_id= ?";
  64.                     ConnectionProvider conn = new DalConnectionProvider();
  65.                     Connection connection;
  66.                     boolean hasAttachment = false;
  67.                     try {
  68.                         connection = conn.getConnection();
  69.                         PreparedStatement ps = connection.prepareStatement(sqlquery);
  70.                         ps.setString(1, "800214");
  71.                         ps.setString(2, re.getId());
  72.                         ResultSet rs = ps.executeQuery();
  73.                         while (rs.next())
  74.                             hasAttachment=true;
  75.  
  76.                     } catch (NoConnectionAvailableException e) {
  77.                         e.printStackTrace();
  78.                         throw new OBException(e.getMessage());
  79.                     } catch (SQLException e) {
  80.                         e.printStackTrace();
  81.                         throw new OBException(e.getMessage());
  82.                     }
  83.                     if (!hasAttachment)
  84.                         throw new OBException("Attachment document is required for procurement of this product");
  85.                 }
  86.             }
  87.  
  88.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  89.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  90.                 //cek apakah dari CL atau VO, jika ya, maka exception
  91.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  92.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  93.                     throw new OBException("@ActionNotAllowedHere@");
  94.  
  95.                 //ubdah dulu docstatus menjadi DR, baru di complete
  96.                 requisition.setDocumentStatus(draftStatus);
  97.                 requisition.setDocumentAction(doc_status_to);
  98.                 OBDal.getInstance().save(requisition);
  99.                 OBDal.getInstance().flush();
  100.  
  101.             } else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  102.                 //cek apakah doc status adalah CO, jika tidak maka exception
  103.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  104.                 if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  105.                     throw new OBException("@ActionNotAllowedHere@");
  106.                 requisition.setDocumentAction(doc_status_to);
  107.                 OBDal.getInstance().save(requisition);
  108.                 OBDal.getInstance().flush();
  109.  
  110.             }
  111.             doExecuteProcedureCall(requisitionID, processID);
  112.  
  113.         }
  114.  
  115.  
  116.     }
  117.  
  118.     @Override
  119.     public String getCoDocumentNo(String recordID, Tab tab) {
  120.         // TODO sementara null dulu
  121.         return null;
  122.     }
  123.  
  124.     @Override
  125.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  126.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  127.                 document_status_to.equalsIgnoreCase(closedStatus))
  128.             return true;
  129.         else
  130.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  131.  
  132.     }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement