Advertisement
tko_pb

GenerateBPSearchKeyCallout 24 agustus

Aug 24th, 2018
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.47 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();
  26.         String SupplierValidation = "SUPPLIER";
  27.  
  28.         Boolean BpIsSupplierValidation;
  29.         BpIsSupplierValidation = BpCategoryName.contains(SupplierValidation);
  30.  
  31.         //get client id role
  32.         String ClientIdFromParameter = Utility.getPreference(info.vars, "ClientIdPreference", null);
  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