Advertisement
tko_pb

OrderActionHandler 4 oktober

Oct 4th, 2018
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. package org.wirabumi.gen.oez.porting;
  2.  
  3. import java.sql.SQLException;
  4. import java.util.List;
  5.  
  6. import org.openbravo.base.exception.OBException;
  7. import org.openbravo.base.model.Entity;
  8. import org.openbravo.base.secureApp.VariablesSecureApp;
  9. import org.openbravo.dal.service.OBDal;
  10. import org.openbravo.database.ConnectionProvider;
  11. import org.openbravo.erpCommon.utility.OBError;
  12. import org.openbravo.erpCommon.utility.Utility;
  13. import org.openbravo.model.common.order.Order;
  14. import org.openbravo.service.db.DalConnectionProvider;
  15. import org.wirabumi.gen.oez.callout.CallGenerateAutoSearchKey;
  16. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  17. import org.openbravo.model.ad.ui.Tab;
  18.  
  19.  
  20.  
  21. public class OrderActionHandler 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 orderProcessID="104";
  28.     private final String waitingRelease1="oez_waitingrelease1";
  29.     private final String waitingRelease2="oez_waitingrelease2";
  30.     private final String waitingRelease3="oez_waitingrelease3";
  31.     private final String waitingRelease4="oez_waitingrelease4";
  32.     private final String waitingRelease5="oez_waitingrelease5";
  33.  
  34.     @Override
  35.     public void doRouting(String adWindowId, String adTabId,
  36.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  37.  
  38.         final ConnectionProvider conn = new DalConnectionProvider();
  39.  
  40.         //berlaku untuk doComplete, doReactive, doClose, dan doVoid
  41.  
  42.         for (String orderID : recordId){
  43.  
  44.             Order order = OBDal.getInstance().get(Order.class, orderID);
  45.             String docstatus=order.getDocumentStatus();
  46.             String docaction=order.getDocumentAction();
  47.             String doc_status = order.getDocumentStatus();
  48.  
  49.             switch(doc_status_to) {
  50.             case "CO" :
  51.             {
  52.                 //cek apakah dari CL atau VO, jika ya, maka exception
  53.                 if (order.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  54.                         order.getDocumentStatus().equalsIgnoreCase(voidStatus))
  55.                     throw new OBException("@ActionNotAllowedHere@");
  56.  
  57.                 //ubdah dulu docstatus menjadi DR, baru di complete
  58.                 order.setDocumentStatus(draftStatus);
  59.                 order.setDocumentAction(doc_status_to);
  60.                 break;
  61.             }
  62.             case "VO":
  63.             case "CL":
  64.             case "RE":
  65.             {
  66.                 boolean draftValidation = false;
  67.                 switch (doc_status) {
  68.                 case "oez_waitingrelease1":
  69.                 case "oez_waitingrelease2":
  70.                 case "oez_waitingrelease3":
  71.                 case "oez_waitingrelease4":
  72.                 case "oez_waitingrelease5":
  73.                     draftValidation = true;
  74.                     if(draftValidation)
  75.                         break;
  76.                     //cek apakah doc status adalah CO, jika tidak maka exception
  77.                     if (!order.getDocumentStatus().equalsIgnoreCase(completeStatus))
  78.                         throw new OBException("@ActionNotAllowedHere@");
  79.                 }
  80.             }
  81.             order.setDocumentAction(doc_status_to);
  82.             break;
  83.             }
  84.  
  85.             OBDal.getInstance().save(order);
  86.             try {
  87.                 OBDal.getInstance().getConnection().commit();
  88.             } catch (SQLException e) {
  89.                 e.printStackTrace();
  90.                 throw new OBException(e.getMessage());
  91.             }
  92.  
  93.             try{
  94.                 OBError oberror = doExecuteProcedureCall(orderID, orderProcessID);
  95.                 if (oberror.getType().equalsIgnoreCase("Error")){
  96.                     String message = oberror.getMessage();
  97.                     //                  message = message.substring(8, message.length()-1);
  98.                     String convertedMessage = Utility.messageBD(conn, message, vars.getLanguage());
  99.                     throw new OBException(convertedMessage);
  100.                 }
  101.  
  102.             }
  103.             catch (OBException e){
  104.                 //exception happen, rollback doc status
  105.                 order.setDocumentStatus(docstatus);
  106.                 order.setDocumentAction(docaction);
  107.                 OBDal.getInstance().save(order);
  108.                 try {
  109.                     OBDal.getInstance().getConnection().commit();
  110.                 } catch (SQLException e2) {
  111.                     e.printStackTrace();
  112.                     throw new OBException(e.getMessage());
  113.                 }
  114.  
  115.                 //throw chain exception
  116.                 e.printStackTrace();
  117.                 throw new OBException(e.getMessage());
  118.             }
  119.  
  120.             OBDal.getInstance().refresh(order);
  121.             docstatus=order.getDocumentStatus();
  122.             boolean processed = order.isProcessed();
  123.             if (processed && !docstatus.equalsIgnoreCase(completeStatus) && doc_status_to.equalsIgnoreCase(completeStatus)){
  124.                 //terproses tapi doc status masih draft
  125.                 //maka ubah docstatus menjadi complete
  126.                 order.setDocumentStatus(doc_status_to);
  127.                 OBDal.getInstance().save(order);
  128.                 try {https://pastebin.com/EMhW1Cfv
  129.                     OBDal.getInstance().getConnection().commit();
  130.                 } catch (SQLException e) {
  131.                     e.printStackTrace();
  132.                     throw new OBException(e.getMessage());
  133.                 }
  134.             }
  135.  
  136.         }
  137.  
  138.     }
  139.  
  140.     @Override
  141.     public String getCoDocumentNo(String recordID, Tab tab) {
  142.         // TODO sementara null dulu
  143.         return null;
  144.     }
  145.  
  146.     @Override
  147.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  148.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  149.                 document_status_to.equalsIgnoreCase(reactiveStatus)||
  150.                 document_status_to.equalsIgnoreCase(closedStatus)||
  151.                 document_status_to.equalsIgnoreCase(voidStatus))
  152.             return true;
  153.         else
  154.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  155.  
  156.     }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement