Advertisement
tko_pb

RequisitionActionHandler 2

Jul 2nd, 2018
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.68 KB | None | 0 0
  1. package org.wirabumi.gen.oez.porting;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5.  
  6. import org.hibernate.criterion.Restrictions;
  7. import org.openbravo.base.exception.OBException;
  8. import org.openbravo.base.model.Entity;
  9. import org.openbravo.base.secureApp.VariablesSecureApp;
  10. import org.openbravo.dal.service.OBCriteria;
  11. import org.openbravo.dal.service.OBDal;
  12. import org.openbravo.model.ad.datamodel.Table;
  13. import org.openbravo.model.ad.ui.Tab;
  14. import org.openbravo.model.ad.utility.Attachment;
  15. import org.openbravo.model.common.plm.ProductCategory;
  16. import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
  17. import org.openbravo.model.procurement.Requisition;
  18. import org.openbravo.model.procurement.RequisitionLine;
  19. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  20.  
  21. public class RequisitionActionHandler extends DocumentRoutingHandlerAction {
  22. private final String reactiveStatus="RE";
  23. private final String completeStatus="CO";
  24. private final String draftStatus="DR";
  25. private final String closedStatus="CL";
  26. private final String voidStatus="VO";
  27. private final String processID="1004400003";
  28.  
  29. @Override
  30. public void doRouting(String adWindowId, String adTabId,
  31. String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  32. if (doc_status_to.equalsIgnoreCase(voidStatus))
  33. throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
  34.  
  35. for (String requisitionID : recordId){
  36.  
  37. /*tiko [langkah-langkah]
  38.  
  39. 1. jika tabel null maka
  40. 2. seleksi list untuk ambil id requisition, dan line dari requisition
  41. 3. seleksi apak line memiliki product category search key "INVESTASI" atau tidak?
  42. 4. jika bernilai investasi dan tidak memiliki attachments maka OBException
  43. */
  44. Tab tab = OBDal.getInstance().get(Tab.class, adTabId);
  45. Table table = tab.getTable();
  46.  
  47. if (table!=null) {
  48. String tableid = table.getId();
  49. OBCriteria<Requisition> resLineCriteria= OBDal.getInstance().createCriteria(Requisition.class);
  50. OBCriteria<Attachment> attachCriteria = OBDal.getInstance().createCriteria(Attachment.class);
  51. attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_TABLE, tableid));
  52. attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_RECORD, requisitionID));
  53.  
  54. List<Requisition> resLineList = resLineCriteria.list();
  55. List<RequisitionLine> RiList = new ArrayList<RequisitionLine>();
  56. for (Requisition re :resLineList )
  57. {
  58. RiList.add((RequisitionLine) re.getProcurementRequisitionLineList());
  59. }
  60.  
  61. List<Attachment> attachList = attachCriteria.list();
  62.  
  63. for (RequisitionLine re : RiList) {
  64. if ( (re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true) && (attachList.size()==0) );
  65. throw new OBException("requisition tidak memiliki atatchments");
  66. }
  67. } /*tiko*/
  68.  
  69. if (doc_status_to.equalsIgnoreCase(completeStatus)){
  70. Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  71. //cek apakah dari CL atau VO, jika ya, maka exception
  72. if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  73. requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  74. throw new OBException("@ActionNotAllowedHere@");
  75.  
  76. //ubdah dulu docstatus menjadi DR, baru di complete
  77. requisition.setDocumentStatus(draftStatus);
  78. requisition.setDocumentAction(doc_status_to);
  79. OBDal.getInstance().save(requisition);
  80. OBDal.getInstance().flush();
  81.  
  82. } else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  83. //cek apakah doc status adalah CO, jika tidak maka exception
  84. Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  85. if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  86. throw new OBException("@ActionNotAllowedHere@");
  87. requisition.setDocumentAction(doc_status_to);
  88. OBDal.getInstance().save(requisition);
  89. OBDal.getInstance().flush();
  90.  
  91. }
  92. doExecuteProcedureCall(requisitionID, processID);
  93.  
  94. }
  95.  
  96.  
  97. }
  98.  
  99. @Override
  100. public String getCoDocumentNo(String recordID, Tab tab) {
  101. // TODO sementara null dulu
  102. return null;
  103. }
  104.  
  105. @Override
  106. public Boolean updateDocumentStatus(Entity entity, List<String> RecordId, String document_status_to,String column){
  107. if (document_status_to.equalsIgnoreCase(completeStatus)||
  108. document_status_to.equalsIgnoreCase(closedStatus))
  109. return true;
  110. else
  111. return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  112.  
  113. }
  114.  
  115. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement