Advertisement
tko_pb

IcsBpSearchKey.java

Jan 28th, 2019
401
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.66 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 org.openbravo.dal.service.OBDal;
  8. import org.openbravo.erpCommon.ad_callouts.SimpleCallout.CalloutInfo;
  9. import org.openbravo.erpCommon.utility.Utility;
  10. import org.openbravo.model.common.businesspartner.Category;
  11.  
  12. public class IcsBpSearchKey implements GenerateBPSearchKey{
  13.  
  14.     @Override
  15.     public String getBPSearchKey(CalloutInfo info)  {
  16.         // TODO Auto-generated method stub
  17.  
  18.         //get key from sub Category inpmProductCategoryId
  19.         String strClientId = info.getStringParameter("inpadClientId", null);
  20.         String bpCategoryID = info.getStringParameter("inpcBpGroupId", null);
  21.        
  22.        
  23.         if (!SupplierIsTrue(info, bpCategoryID)) {
  24.             return null;
  25.         }
  26.         // get preference
  27.         String bpPrefix = Utility.getPreference(info.vars, "BusinessPartnerPrefix", null);
  28.         String bpSuffix = Utility.getPreference(info.vars, "BusinessPartnerSuffix", null);
  29.  
  30.         //getSquence
  31.         String maxSquence = " select max(em_oez_bpartnersquence) as jumlahSquence" +
  32.                 " from c_bpartner " +
  33.                 " where c_bp_group_id=?";
  34.         java.sql.Connection MaxSquenceconn = OBDal.getInstance().getConnection();
  35.         String searchKey = null;
  36.         try {
  37.             PreparedStatement psMaxSquence = MaxSquenceconn.prepareStatement(maxSquence);
  38.             psMaxSquence.setString(1, bpCategoryID);
  39.             ResultSet rsMaxSquence = psMaxSquence.executeQuery();
  40.             int getMaxSquence = 0;
  41.             while (rsMaxSquence.next())
  42.             {
  43.                 getMaxSquence = rsMaxSquence.getInt("jumlahSquence");
  44.             }
  45.             boolean MaxSquenceNotNull =  getMaxSquence > 0;
  46.  
  47.             if (!MaxSquenceNotNull)
  48.             {
  49.                 String strJumlahBPartner = generateSkuSquenceIsNull(strClientId, info);
  50.                 searchKey = bpPrefix+ strJumlahBPartner + bpSuffix;
  51.             }
  52.             else
  53.             {
  54.                 //add searchKey bp
  55.                 int strJumlahmaxsquence = getMaxSquence + 1;
  56.                 searchKey = bpPrefix+ strJumlahmaxsquence + bpSuffix;
  57.  
  58.                 //add strJumlahmaxsquence to em_oezBusinessPartner field
  59.                 Long JumlahBpLong = Long.valueOf(strJumlahmaxsquence);
  60.                 info.addResult("inpemOezBpartnersquence", JumlahBpLong);
  61.             }
  62.         }
  63.         catch (Exception e) {
  64.             e.printStackTrace();
  65.         }
  66.         return searchKey;
  67.     }
  68.    
  69.     public boolean SupplierIsTrue (CalloutInfo info, String bpCategoryID ) {
  70.         //validation bahwa data merupakan supplier
  71.        
  72.         Category bpCategory = OBDal.getInstance().get(Category.class, bpCategoryID);
  73.         String bpCategoryName = bpCategory.getName().toLowerCase();
  74.  
  75.         String supplierValidation = Utility.getPreference(info.vars, "supplierValidation", null);
  76.         return bpCategoryName.contains(supplierValidation);
  77.     }
  78.    
  79.     public String generateSkuSquenceIsNull(String strClientId, CalloutInfo info) {
  80.         //get increment number
  81.         String sql = " select count(*) as JumlahBP " +
  82.                 " from c_bpartner as a " +
  83.                 " inner join c_bp_group as b on a.c_bp_group_id = b.c_bp_group_id " +
  84.                 " where a.ad_client_id=? " +
  85.                 " and lower(b.\"name\") like '%supplier%' ";
  86.         java.sql.Connection conn = OBDal.getInstance().getConnection();
  87.         String strJumlahBPartner = null;
  88.         try {
  89.             PreparedStatement ps = conn.prepareStatement(sql);
  90.             ps.setString(1, strClientId);
  91.             ResultSet rs = ps.executeQuery();
  92.             int JumlahBP = 0;
  93.             while (rs.next()) {
  94.                 JumlahBP = rs.getInt("JumlahBP");
  95.             }
  96.             JumlahBP++;
  97.  
  98.             DecimalFormat myFormatter = new DecimalFormat("00000000");
  99.             strJumlahBPartner = myFormatter.format(JumlahBP);
  100.  
  101.             //add jumlahBP to em_oezBusinessPartner field
  102.             Long JumlahBpLong = Long.valueOf(JumlahBP);
  103.             info.addResult("inpemOezBpartnersquence", JumlahBpLong);
  104.         }
  105.         catch (Exception e) {
  106.             e.printStackTrace();
  107.         }  
  108.         return strJumlahBPartner;
  109.     }
  110.  
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement