Advertisement
tko_pb

GenerateBPSearchKeyCallout6september

Sep 5th, 2018
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. package org.wirabumi.gen.oez.callout;
  2.  
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.text.DecimalFormat;
  6.  
  7. import javax.servlet.ServletException;
  8.  
  9. import org.openbravo.dal.service.OBDal;
  10. import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
  11. import org.openbravo.erpCommon.utility.Utility;
  12. import org.openbravo.model.common.businesspartner.Category;
  13.  
  14. public class GenerateBPSearchKeyCallout extends SimpleCallout {
  15.  
  16.     @Override
  17.     protected void execute(CalloutInfo info) throws ServletException {
  18.  
  19.         //get key from sub Category inpmProductCategoryId
  20.         String strClientId = info.getStringParameter("inpadClientId", null);
  21.  
  22.         //validation bahwa data merupakan supplier
  23.         String bpCategoryID = info.getStringParameter("inpcBpGroupId", null);
  24.         Category bpCategory = OBDal.getInstance().get(Category.class, bpCategoryID);
  25.         String bpCategoryName = bpCategory.getName().toLowerCase();
  26.  
  27.         String supplierValidation = Utility.getPreference(info.vars, "supplierValidation", null);
  28.         Boolean bpIsSupplierValidation;
  29.         bpIsSupplierValidation = bpCategoryName.contains(supplierValidation);
  30.  
  31.         //client id Idol Mart
  32.         String ClientIdIdolMartGroup = "D089DFFA729F4A22816BD8838AB0813C";
  33.         String ClientIdDevIdolMartGroup = "9FEF116B9BA24538AC481B809CC750FF";
  34.  
  35.         //id client id role match with client id from preference
  36.         if ( (strClientId.equalsIgnoreCase(ClientIdIdolMartGroup) || (strClientId.equalsIgnoreCase(ClientIdDevIdolMartGroup))) ) {
  37.             if (bpIsSupplierValidation) {
  38.                 // get preference
  39.                 String bpPrefix = Utility.getPreference(info.vars, "BusinessPartnerPrefix", null);
  40.                 String bpSuffix = Utility.getPreference(info.vars, "BusinessPartnerSuffix", null);
  41.  
  42.                 //getSquence
  43.                 String maxSquence = " select max(em_oez_bpartnersquence) as jumlahSquence" +
  44.                         " from c_bpartner " +
  45.                         " where c_bp_group_id=?";
  46.                 java.sql.Connection MaxSquenceconn = OBDal.getInstance().getConnection();
  47.                 try {
  48.                     PreparedStatement psMaxSquence = MaxSquenceconn.prepareStatement(maxSquence);
  49.                     psMaxSquence.setString(1, bpCategoryID);
  50.                     ResultSet rsMaxSquence = psMaxSquence.executeQuery();
  51.                     int getMaxSquence = 0;
  52.                     while (rsMaxSquence.next())
  53.                     {
  54.                         getMaxSquence = rsMaxSquence.getInt("jumlahSquence");
  55.                     }
  56.                     boolean MaxSquenceNotNull =  getMaxSquence > 0;
  57.  
  58.                     if (!MaxSquenceNotNull)
  59.                     {
  60.                         String strJumlahBPartner = generateSkuSquenceIsNull(strClientId, info);
  61.                         String searchKey = bpPrefix+ strJumlahBPartner + bpSuffix;
  62.                         info.addResult("inpvalue", searchKey);
  63.                     }
  64.                     else
  65.                     {
  66.                         //add searchKey bp
  67.                         int strJumlahmaxsquence = getMaxSquence + 1;
  68.                         String searchKey = bpPrefix+ strJumlahmaxsquence + bpSuffix;
  69.                         info.addResult("inpvalue", searchKey);
  70.  
  71.                         //add strJumlahmaxsquence to em_oezBusinessPartner field
  72.                         Long JumlahBpLong = Long.valueOf(strJumlahmaxsquence);
  73.                         info.addResult("inpemOezBpartnersquence", JumlahBpLong);
  74.                     }
  75.                 }
  76.                 catch (Exception e) {
  77.                     e.printStackTrace();
  78.                 }
  79.             }
  80.  
  81.         }
  82.         else
  83.         {
  84.             return;
  85.         }
  86.     }
  87.  
  88.  
  89.  
  90.     public String generateSkuSquenceIsNull(String strClientId, CalloutInfo info) {
  91.         //get increment number
  92.         String sql = " select count(*) as JumlahBP " +
  93.                 " from c_bpartner as a " +
  94.                 " inner join c_bp_group as b on a.c_bp_group_id = b.c_bp_group_id " +
  95.                 " where a.ad_client_id=? " +
  96.                 " and lower(b.\"name\") like '%supplier%' ";
  97.         java.sql.Connection conn = OBDal.getInstance().getConnection();
  98.         String strJumlahBPartner = null;
  99.         try {
  100.             PreparedStatement ps = conn.prepareStatement(sql);
  101.             ps.setString(1, strClientId);
  102.             ResultSet rs = ps.executeQuery();
  103.             int JumlahBP = 0;
  104.             while (rs.next()) {
  105.                 JumlahBP = rs.getInt("JumlahBP");
  106.             }
  107.             JumlahBP++;
  108.  
  109.             DecimalFormat myFormatter = new DecimalFormat("00000000");
  110.             strJumlahBPartner = myFormatter.format(JumlahBP);
  111.  
  112.             //add jumlahBP to em_oezBusinessPartner field
  113.             Long JumlahBpLong = Long.valueOf(JumlahBP);
  114.             info.addResult("inpemOezBpartnersquence", JumlahBpLong);
  115.         }
  116.         catch (Exception e) {
  117.             e.printStackTrace();
  118.         }  
  119.         return strJumlahBPartner;
  120.     }
  121.  
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement