Advertisement
tko_pb

GenerateBPSearchKeyCallout 25 agustus

Aug 25th, 2018
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.51 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 ClientIdFromParameter = "0E5A159A4D88441F8B5EEF4A90366669";
  33.  
  34.         //id client id role match with client id from preference
  35.         if (strClientId.equalsIgnoreCase(ClientIdFromParameter)) {
  36.             if (bpIsSupplierValidation) {
  37.                 // get preference
  38.                 String bpPrefix = Utility.getPreference(info.vars, "BusinessPartnerPrefix", null);
  39.                 String bpSuffix = Utility.getPreference(info.vars, "BusinessPartnerSuffix", null);
  40.  
  41.                 //get increment number
  42.                 String sql = " select count(*) as JumlahBP " +
  43.                         " from c_bpartner as a " +
  44.                         " inner join c_bp_group as b on a.ad_client_id = b.ad_client_id " +
  45.                         " where a.ad_client_id=? " +
  46.                         " and lower(b.\"name\") like '%supplier%' ";
  47.                 java.sql.Connection conn = OBDal.getInstance().getConnection();
  48.                 try {
  49.                     PreparedStatement ps = conn.prepareStatement(sql);
  50.                     ps.setString(1, strClientId);
  51.                     ResultSet rs = ps.executeQuery();
  52.                     int JumlahBP = 0;
  53.                     while (rs.next()) {
  54.                         JumlahBP = rs.getInt("JumlahBP");
  55.                     }
  56.                     JumlahBP++;
  57.  
  58.                     DecimalFormat myFormatter = new DecimalFormat("00000000");
  59.                     String strJumlahBPartner = myFormatter.format(JumlahBP);
  60.                     String searchKey = bpPrefix+ strJumlahBPartner + bpSuffix;
  61.                     info.addResult("inpvalue", searchKey);
  62.                 }
  63.                 catch (Exception e) {
  64.                     e.printStackTrace();
  65.                 }  
  66.             }
  67.  
  68.         }
  69.         else
  70.         {
  71.             return;
  72.         }
  73.     }
  74.  
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement