Advertisement
tko_pb

InoutActionHandler 25 september 2

Sep 25th, 2018
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.81 KB | None | 0 0
  1. package org.wirabumi.gen.oez.porting;
  2.  
  3. import java.math.BigDecimal;
  4. import java.math.BigInteger;
  5. import java.sql.SQLException;
  6. import java.util.List;
  7.  
  8. import org.openbravo.base.exception.OBException;
  9. import org.openbravo.base.model.Entity;
  10. import org.openbravo.base.secureApp.VariablesSecureApp;
  11. import org.openbravo.dal.service.OBDal;
  12. import org.openbravo.erpCommon.utility.OBError;
  13. import org.openbravo.model.ad.ui.Tab;
  14. import org.openbravo.model.common.order.Order;
  15. import org.openbravo.model.common.order.OrderLine;
  16. import org.openbravo.model.materialmgmt.transaction.ShipmentInOut;
  17. import org.openbravo.model.materialmgmt.transaction.ShipmentInOutLine;
  18. import org.wirabumi.gen.oez.event.DocumentRoutingHandlerAction;
  19.  
  20. public class InoutActionHandler 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 inoutProcessID="109";
  27.  
  28.     @Override
  29.     public void doRouting(String adWindowId, String adTabId,
  30.             String doc_status_to, VariablesSecureApp vars, List<String> recordId) {
  31.         if (doc_status_to.equalsIgnoreCase(reactiveStatus))
  32.             throw new OBException("@ActionNotAllowedHere@"); //shipment inout tidak boleh di reactive
  33.  
  34.         for (String inoutID : recordId){
  35.             ShipmentInOut inout = OBDal.getInstance().get(ShipmentInOut.class, inoutID);
  36.             String docstatus=inout.getDocumentStatus();
  37.             String docaction=inout.getDocumentAction();
  38.  
  39.             if (doc_status_to.equalsIgnoreCase(completeStatus)){
  40.  
  41.                 for (ShipmentInOutLine inOutLineid : inout.getMaterialMgmtShipmentInOutLineList() ) {  
  42.  
  43.                     if (inout.getSalesOrder() == null ) {
  44.                         continue;
  45.                     }
  46.  
  47.                     BigDecimal orderQuantityGR = inOutLineid.getMovementQuantity();
  48.                     OrderLine lineGoodReceipt =  inOutLineid.getSalesOrderLine();  
  49.  
  50.                     BigDecimal productOverDelivery = lineGoodReceipt.getProduct().getOezOverDelivery();
  51.                     if (productOverDelivery == null)
  52.                     {  
  53.                         productOverDelivery = new BigDecimal (0); // jika over null maka over akan di set menjadi 0
  54.                     }    
  55.                     BigDecimal orderQuantityPO = lineGoodReceipt.getOrderedQuantity();
  56.                     BigDecimal reservedQuantity = lineGoodReceipt.getReservedQuantity();
  57.  
  58.                     BigDecimal bagi100 = BigDecimal.valueOf(100);
  59.                     BigDecimal hasilPoPlusOver =  productOverDelivery.divide(bagi100).multiply(orderQuantityPO).add(orderQuantityPO);
  60.                     BigDecimal reserVerif = hasilPoPlusOver.add(reservedQuantity);
  61.  
  62.                     if (orderQuantityGR.intValue() > reserVerif.intValue())
  63.                     {
  64.                         throw new OBException("Value of order Good Reciept is higher than Purchase Order over delivery");  
  65.                     }
  66.  
  67.                 }  
  68.  
  69.                 //cek apakah dari CL atau VO, jika ya, maka exception
  70.                 if (inout.getDocumentStatus().equalsIgnoreCase(closedStatus)||
  71.                         inout.getDocumentStatus().equalsIgnoreCase(voidStatus))
  72.                     throw new OBException("@ActionNotAllowedHere@");
  73.  
  74.                 //ubdah dulu docstatus menjadi DR, baru di complete
  75.                 inout.setDocumentStatus(draftStatus);
  76.                 inout.setDocumentAction(doc_status_to);
  77.                 OBDal.getInstance().save(inout);
  78.                 try {
  79.                     OBDal.getInstance().getConnection().commit();
  80.                 } catch (SQLException e) {
  81.                     e.printStackTrace();
  82.                     throw new OBException(e.getMessage());
  83.                 }
  84.  
  85.             } else if (doc_status_to.equalsIgnoreCase(voidStatus)||
  86.                     doc_status_to.equalsIgnoreCase(closedStatus)){
  87.                 //cek apakah doc status adalah CO, jika tidak maka exception
  88.                 if (!inout.getDocumentStatus().equalsIgnoreCase(completeStatus))
  89.                     throw new OBException("@ActionNotAllowedHere@");
  90.                 inout.setDocumentAction(doc_status_to);
  91.                 if (doc_status_to.equalsIgnoreCase(voidStatus))
  92.                     inout.setDocumentAction("RC"); //void dalam document routing adalah VO, tapi dalam invoice adalah RC
  93.                 OBDal.getInstance().save(inout);
  94.                 try {
  95.                     OBDal.getInstance().getConnection().commit();
  96.                 } catch (SQLException e) {
  97.                     e.printStackTrace();
  98.                     throw new OBException(e.getMessage());
  99.                 }
  100.  
  101.             }
  102.             try{
  103.                 OBError oberror = doExecuteProcedureCall(inoutID, inoutProcessID);
  104.                 if (oberror.getType().equals("Error"))
  105.                     throw new OBException(oberror.getMessage());
  106.             }
  107.             catch (OBException e){
  108.                 //exception happen, rollback doc status
  109.                 inout.setDocumentStatus(docstatus);
  110.                 inout.setDocumentAction(docaction);
  111.                 OBDal.getInstance().save(inout);
  112.                 try {
  113.                     OBDal.getInstance().getConnection().commit();
  114.                 } catch (SQLException e2) {
  115.                     e.printStackTrace();
  116.                     throw new OBException(e.getMessage());
  117.                 }
  118.  
  119.                 //throw chain exception
  120.                 e.printStackTrace();
  121.                 throw new OBException(e.getMessage());
  122.             }
  123.  
  124.             OBDal.getInstance().refresh(inout);
  125.             docstatus=inout.getDocumentStatus();
  126.             boolean processed = inout.isProcessed();
  127.             if (processed && !docstatus.equalsIgnoreCase(completeStatus) && doc_status_to.equalsIgnoreCase(completeStatus)){
  128.                 //terproses tapi doc status masih draft
  129.                 //maka ubah docstatus menjadi complete
  130.                 inout.setDocumentStatus(doc_status_to);
  131.                 OBDal.getInstance().save(inout);
  132.                 try {
  133.                     OBDal.getInstance().getConnection().commit();
  134.                 } catch (SQLException e) {
  135.                     e.printStackTrace();
  136.                     throw new OBException(e.getMessage());
  137.                 }
  138.             }
  139.  
  140.         }
  141.  
  142.     }
  143.  
  144.     @Override
  145.     public String getCoDocumentNo(String recordID, Tab tab) {
  146.         // TODO semengtara null dulu
  147.         return null;
  148.     }
  149.  
  150.     @Override
  151.     public Boolean updateDocumentStatus(Entity entity,  List<String> RecordId, String document_status_to,String column){
  152.         if (document_status_to.equalsIgnoreCase(completeStatus)||
  153.                 document_status_to.equalsIgnoreCase(closedStatus)||
  154.                 document_status_to.equalsIgnoreCase(voidStatus))
  155.             return true;
  156.         else
  157.             return super.updateDocumentStatus(entity, RecordId, document_status_to, column);
  158.  
  159.     }
  160.  
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement