Advertisement
tko_pb

RequisitionActionHandler 5

Jul 4th, 2018
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.73 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.             /*tiko*/
  57.             Tab tab = OBDal.getInstance().get(Tab.class, adTabId);
  58.             Table table = tab.getTable();
  59.             String tableid = table.getId();
  60.  
  61.  
  62.             Requisition requi = OBDal.getInstance().get(Requisition.class, requisitionID);
  63.             List <RequisitionLine> requiL = requi.getProcurementRequisitionLineList();
  64.  
  65.             for (RequisitionLine re : requiL) {
  66.                 if (re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true) {
  67.                    
  68.                     /*OBCriteria<Attachment> attachCriteria = OBDal.getInstance().createCriteria(Attachment.class);
  69.                     attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_TABLE, tableid));
  70.                     BaseOBObject baseobobject = OBDal.getInstance().get(BaseOBObject.class, re.getId());
  71.                     attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_RECORD, baseobobject));
  72.                     List<Attachment> attachList = attachCriteria.list();
  73.                     if (attachList.size()==0)
  74.                         throw new OBException("Attachment document is required for procurement of this product");
  75.                      */
  76.  
  77.                     String sqlquery = "select count(*) from c_file"
  78.                             + " where ad_table_id= ?"
  79.                             + " and ad_record_id= ?";
  80.                     ConnectionProvider conn = new DalConnectionProvider();
  81.                     Connection connection;
  82.                     boolean hasAttachment = false;
  83.                     try {
  84.                         connection = conn.getConnection();
  85.                         PreparedStatement ps = connection.prepareStatement(sqlquery);
  86.                         ps.setString(1, tableid);
  87.                         ps.setString(2, re.getId());
  88.                         ResultSet rs = ps.executeQuery();
  89.                         while (rs.next())
  90.                             hasAttachment=true;
  91.  
  92.                     } catch (NoConnectionAvailableException e) {
  93.                         e.printStackTrace();
  94.                         throw new OBException(e.getMessage());
  95.                     } catch (SQLException e) {
  96.                         e.printStackTrace();
  97.                         throw new OBException("Attachment document is required for procurement of this product");
  98.                     }
  99.                 }
  100.             }
  101.             /*tiko*/
  102.  
  103.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  104.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  105.                 //cek apakah dari CL atau VO, jika ya, maka exception
  106.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  107.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  108.                     throw new OBException("@ActionNotAllowedHere@");
  109.  
  110.                 //ubdah dulu docstatus menjadi DR, baru di complete
  111.                 requisition.setDocumentStatus(draftStatus);
  112.                 requisition.setDocumentAction(doc_status_to);
  113.                 OBDal.getInstance().save(requisition);
  114.                 OBDal.getInstance().flush();
  115.  
  116.             } else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  117.                 //cek apakah doc status adalah CO, jika tidak maka exception
  118.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  119.                 if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  120.                     throw new OBException("@ActionNotAllowedHere@");
  121.                 requisition.setDocumentAction(doc_status_to);
  122.                 OBDal.getInstance().save(requisition);
  123.                 OBDal.getInstance().flush();
  124.  
  125.             }
  126.             doExecuteProcedureCall(requisitionID, processID);
  127.  
  128.         }
  129.  
  130.  
  131.     }
  132.  
  133.     @Override
  134.     public String getCoDocumentNo(String recordID, Tab tab) {
  135.         // TODO sementara null dulu
  136.         return null;
  137.     }
  138.  
  139.     @Override
  140.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  141.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  142.                 document_status_to.equalsIgnoreCase(closedStatus))
  143.             return true;
  144.         else
  145.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  146.  
  147.     }
  148.  
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement