Advertisement
tko_pb

RequisitionActionHandler 3

Jul 3rd, 2018
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.94 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.     /*tiko [langkah-langkah]
  30.    
  31.       1. jika tabel null maka
  32.       2. seleksi list  untuk ambil id requisition,  dan line dari requisition yang sedang approval dengan record id
  33.       3. seleksi apak line memiliki product category search key "INVESTASI" atau tidak? * done
  34.       4. jika bernilai investasi dan tidak memiliki attachments maka OBException * done
  35.      */
  36.    
  37.     @Override
  38.     public void doRouting(String adWindowId, String adTabId,
  39.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  40.         if (doc_status_to.equalsIgnoreCase(voidStatus))
  41.             throw new OBException("@ActionNotAllowedHere@"); //requisition tidak boleh di void
  42.        
  43.         for (String requisitionID : recordId){
  44.            
  45.             /*tiko*/
  46.             Tab tab = OBDal.getInstance().get(Tab.class, adTabId);
  47.             Table table = tab.getTable();
  48.             String tableid = table.getId();
  49.            
  50.             Requisition requi = OBDal.getInstance().get(Requisition.class, recordId);
  51.             List<RequisitionLine> requiLine = requi.getProcurementRequisitionLineList();
  52.                
  53.                 OBCriteria<Requisition> resLineCriteria= OBDal.getInstance().createCriteria(Requisition.class);
  54.                 OBCriteria<Attachment> attachCriteria = OBDal.getInstance().createCriteria(Attachment.class);              
  55.                 attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_TABLE, tableid));
  56.                 attachCriteria.add(Restrictions.eq(Attachment.PROPERTY_RECORD, requiLine));
  57.                
  58.                
  59.                              
  60.                 List<Requisition> resLineList = resLineCriteria.list();
  61.                 List<RequisitionLine> RiList = new ArrayList<RequisitionLine>();
  62.                
  63.                
  64.                 if (Requisition.getProcurementRequisitionLineList());
  65.                 for (Requisition re : recordId) {
  66.                     RiList.add();
  67.                 }
  68.                      
  69.                 List<Attachment> attachList = attachCriteria.list();
  70.                 for (RequisitionLine re : RiList) {
  71.                         if ( (re.getProduct().getProductCategory().getSearchKey().equalsIgnoreCase("INVESTASI") ==true) && (attachList.size()==0) );
  72.                              throw new OBException("Attachment document is required for procurement of this product");
  73.                 }
  74.              /*tiko*/
  75.                    
  76.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  77.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  78.                 //cek apakah dari CL atau VO, jika ya, maka exception
  79.                 if (requisition.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  80.                         requisition.getDocumentStatus().equalsIgnoreCase(voidStatus))
  81.                     throw new OBException("@ActionNotAllowedHere@");
  82.                
  83.                 //ubdah dulu docstatus menjadi DR, baru di complete
  84.                 requisition.setDocumentStatus(draftStatus);
  85.                 requisition.setDocumentAction(doc_status_to);
  86.                 OBDal.getInstance().save(requisition);
  87.                 OBDal.getInstance().flush();
  88.                
  89.             } else if (doc_status_to.equalsIgnoreCase(reactiveStatus)){
  90.                 //cek apakah doc status adalah CO, jika tidak maka exception
  91.                 Requisition requisition = OBDal.getInstance().get(Requisition.class, requisitionID);
  92.                 if (!requisition.getDocumentStatus().equalsIgnoreCase(completeStatus))
  93.                     throw new OBException("@ActionNotAllowedHere@");
  94.                 requisition.setDocumentAction(doc_status_to);
  95.                 OBDal.getInstance().save(requisition);
  96.                 OBDal.getInstance().flush();
  97.                
  98.             }
  99.             doExecuteProcedureCall(requisitionID, processID);
  100.            
  101.         }
  102.        
  103.  
  104.     }
  105.  
  106.     @Override
  107.     public String getCoDocumentNo(String recordID, Tab tab) {
  108.         // TODO sementara null dulu
  109.         return null;
  110.     }
  111.    
  112.     @Override
  113.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  114.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  115.                 document_status_to.equalsIgnoreCase(closedStatus))
  116.             return true;
  117.         else
  118.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  119.        
  120.     }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement