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().toLowerCase();
- String supplierValidation = Utility.getPreference(info.vars, "supplierValidation", null);
- Boolean bpIsSupplierValidation;
- bpIsSupplierValidation = bpCategoryName.contains(supplierValidation);
- //client id Idol Mart
- String ClientIdIdolMartGroup = "D089DFFA729F4A22816BD8838AB0813C";
- String ClientIdDevIdolMartGroup = "9FEF116B9BA24538AC481B809CC750FF";
- //id client id role match with client id from preference
- if ( (strClientId.equalsIgnoreCase(ClientIdIdolMartGroup) || (strClientId.equalsIgnoreCase(ClientIdDevIdolMartGroup))) ) {
- if (bpIsSupplierValidation) {
- // get preference
- String bpPrefix = Utility.getPreference(info.vars, "BusinessPartnerPrefix", null);
- String bpSuffix = Utility.getPreference(info.vars, "BusinessPartnerSuffix", null);
- //getSquence
- String maxSquence = " select max(em_oez_bpartnersquence) as jumlahSquence" +
- " from c_bpartner " +
- " where c_bp_group_id=?";
- java.sql.Connection MaxSquenceconn = OBDal.getInstance().getConnection();
- try {
- PreparedStatement psMaxSquence = MaxSquenceconn.prepareStatement(maxSquence);
- psMaxSquence.setString(1, bpCategoryID);
- ResultSet rsMaxSquence = psMaxSquence.executeQuery();
- int getMaxSquence = 0;
- while (rsMaxSquence.next())
- {
- getMaxSquence = rsMaxSquence.getInt("jumlahSquence");
- }
- boolean MaxSquenceNotNull = getMaxSquence > 0;
- if (!MaxSquenceNotNull)
- {
- String strJumlahBPartner = generateSkuSquenceIsNull(strClientId, info);
- String searchKey = bpPrefix+ strJumlahBPartner + bpSuffix;
- info.addResult("inpvalue", searchKey);
- }
- else
- {
- //add searchKey bp
- int strJumlahmaxsquence = getMaxSquence + 1;
- String searchKey = bpPrefix+ strJumlahmaxsquence + bpSuffix;
- info.addResult("inpvalue", searchKey);
- //add strJumlahmaxsquence to em_oezBusinessPartner field
- Long JumlahBpLong = Long.valueOf(strJumlahmaxsquence);
- info.addResult("inpemOezBpartnersquence", JumlahBpLong);
- }
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
- else
- {
- return;
- }
- }
- public String generateSkuSquenceIsNull(String strClientId, CalloutInfo info) {
- //get increment number
- String sql = " select count(*) as JumlahBP " +
- " from c_bpartner as a " +
- " inner join c_bp_group as b on a.c_bp_group_id = b.c_bp_group_id " +
- " where a.ad_client_id=? " +
- " and lower(b.\"name\") like '%supplier%' ";
- java.sql.Connection conn = OBDal.getInstance().getConnection();
- String strJumlahBPartner = null;
- 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");
- strJumlahBPartner = myFormatter.format(JumlahBP);
- //add jumlahBP to em_oezBusinessPartner field
- Long JumlahBpLong = Long.valueOf(JumlahBP);
- info.addResult("inpemOezBpartnersquence", JumlahBpLong);
- }
- catch (Exception e) {
- e.printStackTrace();
- }
- return strJumlahBPartner;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement