Advertisement
tko_pb

GenerateBPSearchKeyCallout

Aug 21st, 2018
271
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.72 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.BusinessPartner;
  13.  
  14. public class GenerateBPSearchKeyCallout extends SimpleCallout {
  15.  
  16.     @Override
  17.     protected void execute(CalloutInfo info) throws ServletException {
  18.        
  19.         BusinessPartner bp = OBDal.getInstance().get(BusinessPartner.class, info);
  20.         Boolean bpValid = bp.isCustomer();
  21.        
  22.         //get key from sub Category inpmProductCategoryId
  23.         String strClientId = info.getStringParameter("inpadClientId", null);
  24.        
  25.         // get preference
  26.         String bpPrefix = Utility.getPreference(info.vars, "BusinessPartnerPrefix", null);
  27.         String bpSuffix = Utility.getPreference(info.vars, "BusinessPartnerSuffix", null);
  28.        
  29.         //get increment number
  30.         String sql = "select count(*) as JumlahBP" +
  31.                      " from c_bpartner" +
  32.                      " where ad_client_id=?";
  33.         java.sql.Connection conn = OBDal.getInstance().getConnection();
  34.         try {
  35.             PreparedStatement ps = conn.prepareStatement(sql);
  36.             ps.setString(1, strClientId);
  37.             ResultSet rs = ps.executeQuery();
  38.             int JumlahBP = 0;
  39.             while (rs.next()) {
  40.                 JumlahBP = rs.getInt("JumlahBP");
  41.             }
  42.             JumlahBP++;
  43.            
  44.             DecimalFormat myFormatter = new DecimalFormat("00000000");
  45.             String strJumlahBPartner = myFormatter.format(JumlahBP);
  46.             String searchKey = bpPrefix+ strJumlahBPartner + bpSuffix;
  47.             info.addResult("inpvalue", searchKey);
  48.         }
  49.         catch (Exception e) {
  50.             e.printStackTrace();
  51.         }      
  52.        
  53.     }
  54.  
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement