Advertisement
tko_pb

RequisitionActionHandler 13 September Bagian 4

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