Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package org.wirabumi.gen.oez.callout;
- import java.sql.PreparedStatement;
- import java.sql.ResultSet;
- import java.text.DecimalFormat;
- import javax.servlet.ServletException;
- import org.openbravo.dal.service.OBDal;
- import org.openbravo.erpCommon.ad_callouts.SimpleCallout;
- import org.openbravo.erpCommon.utility.Utility;
- import org.openbravo.model.common.businesspartner.Category;
- public class GenerateBPSearchKeyCallout extends SimpleCallout {
- @Override
- protected void execute(CalloutInfo info) throws ServletException {
- //get key from sub Category inpmProductCategoryId
- String strClientId = info.getStringParameter("inpadClientId", null);
- //validation bahwa data merupakan supplier
- String BpCategoryID = info.getStringParameter("inpcBpGroupId", null);
- Category BpCategory = OBDal.getInstance().get(Category.class, BpCategoryID);
- String BpCategoryName = BpCategory.getName();
- String SupplierValidation = "SUPPLIER";
- Boolean BpIsSupplierValidation;
- BpIsSupplierValidation = BpCategoryName.contains(SupplierValidation);
- //get client id role
- String ClientIdFromParameter = Utility.getPreference(info.vars, "ClientIdPreference", null);
- //id client id role match with client id from preference
- if (strClientId.equalsIgnoreCase(ClientIdFromParameter)) {
- if (BpIsSupplierValidation) {
- // get preference
- String bpPrefix = Utility.getPreference(info.vars, "BusinessPartnerPrefix", null);
- String bpSuffix = Utility.getPreference(info.vars, "BusinessPartnerSuffix", null);
- //get increment number
- String sql = " select count(*) as JumlahBP " +
- " from c_bpartner as a " +
- " inner join c_bp_group as b on a.ad_client_id = b.ad_client_id " +
- " where a.ad_client_id=? " +
- " and lower(b.\"name\") like '%supplier%' ";
- java.sql.Connection conn = OBDal.getInstance().getConnection();
- try {
- PreparedStatement ps = conn.prepareStatement(sql);
- ps.setString(1, strClientId);
- ResultSet rs = ps.executeQuery();
- int JumlahBP = 0;
- while (rs.next()) {
- JumlahBP = rs.getInt("JumlahBP");
- }
- JumlahBP++;
- DecimalFormat myFormatter = new DecimalFormat("00000000");
- String strJumlahBPartner = myFormatter.format(JumlahBP);
- String searchKey = bpPrefix+ strJumlahBPartner + bpSuffix;
- info.addResult("inpvalue", searchKey);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- else
- {
- return;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement