Advertisement
tko_pb

RequisitionActionHandler 4

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