package com.weaver.seconddev.interfaces.workflow.action;

import com.sap.conn.jco.JCoDestination;
import com.sap.conn.jco.JCoFunction;
import com.sap.conn.jco.JCoTable;
import com.weaver.common.i18n.tool.util.I18nContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.conn.RecordSetTrans;

public class ZOA_MM_CONDREC_RFC {

    private static final Logger logger_bebbbf11 = LoggerFactory.getLogger(ZOA_MM_CONDREC_RFC.class);

    private JCoDestination destination;

    private String[] retstr;

    public ZOA_MM_CONDREC_RFC() {
        new SAPConn();
        destination = SAPConn.getJCoDestination();
        retstr = null;
    }

    public String[] Getexecute(String gsdm, String[][] as) {
        retstr = new String[2];
        try {
            RecordSetTrans recordsettrans = I18nContextUtil.getBean(RecordSetTrans.class);
            recordsettrans.setAutoCommit(false);
            JCoFunction jcofunction = destination.getRepository().getFunction("ZOA_MM_CONDREC_RFC");
            if (jcofunction == null) {
                System.out.println("ZOA_MM_CONDREC_RFC not found in SAP.");
                retstr[0] = "E";
                retstr[1] = "ZOA_MM_CONDREC_RFC not found in SAP.";
            } else {
                jcofunction.getImportParameterList().setValue("I_BUKRS", gsdm);
                JCoTable jcotable = jcofunction.getTableParameterList().getTable("T_ITEM");
                for (int i = 0; i < as.length; i++) {
                    jcotable.appendRow();
                    jcotable.setValue("WGLIF", as[i][0]);
                    jcotable.setValue("DATBI", as[i][1]);
                    jcotable.setValue("DATAB", as[i][2]);
                    jcotable.setValue("KBETR", as[i][3]);
                    jcotable.setValue("KMEIN", as[i][4]);
                    jcotable.setValue("KPEIN", as[i][5]);
                    jcotable.setValue("KONWA", as[i][6]);
                    jcotable.setValue("LOEVM_KO", as[i][7]);
                    jcotable.setValue("KNUMH", as[i][8]);
                }
                try {
                    jcofunction.execute(destination);
                    retstr[0] = jcofunction.getExportParameterList().getValue("E_STATUS").toString();
                    retstr[1] = jcofunction.getExportParameterList().getValue("E_MESSAGE").toString();
                } catch (Exception exception1) {
                    retstr[0] = "E";
                    retstr[1] = exception1.toString();
                }
            }
            return retstr;
        } catch (Exception exception) {
            retstr[0] = "E";
            retstr[1] = exception.getMessage();
        }
        return retstr;
    }
}
