Advertisement
tko_pb

RequisitionActionHandler 13 September Bagian 3

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