Advertisement
tko_pb

OrderActionHandler

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