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 java.lang.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.weaver.verupgrade.general.BaseBean;

public class ZOA_FI_IORD_RFC extends BaseBean {

    private static final Logger logger_97683e92 = LoggerFactory.getLogger(ZOA_FI_IORD_RFC.class);

    private JCoDestination destination;

    private String[][] retstr;

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

    public String[][] Getexecute(String flag, String[][] as) {
        retstr = new String[as.length][3];
        String state = "";
        String message = "";
        try {
            JCoFunction jcofunction = destination.getRepository().getFunction("ZOA_FI_IORD_RFC");
            if (jcofunction == null) {
                System.out.println("ZOA_FI_IORD_RFC not found in SAP.");
                retstr[0][0] = "E";
                retstr[0][1] = "ZOA_FI_IORD_RFC not found in SAP.";
            } else {
                jcofunction.getImportParameterList().setValue("TESTRUN", flag);
                for (int i = 0; i < as.length; i++) {
                    JCoTable jcotable = jcofunction.getTableParameterList().getTable("T_ITEM");
                    jcotable.clear();
                    jcotable.appendRow();
                    jcotable.setValue("KOKRS", as[i][0]);
                    jcotable.setValue("AUART", as[i][1]);
                    jcotable.setValue("BUKRS", as[i][2]);
                    jcotable.setValue("WERKS", as[i][3]);
                    jcotable.setValue("PRCTR", as[i][4]);
                    jcotable.setValue("KOSTV", as[i][5]);
                    jcotable.setValue("KTEXT", as[i][6]);
                    jcotable.setValue("USER0", as[i][7]);
                    jcotable.setValue("USER1", as[i][8]);
                    jcotable.setValue("USER2", as[i][9]);
                    jcotable.setValue("USER3", as[i][10]);
                    jcotable.setValue("USER4", as[i][11]);
                    jcotable.setValue("WAERS", as[i][12]);
                    jcotable.setValue("USER5", as[i][13]);
                    jcotable.setValue("USER6", as[i][14]);
                    jcotable.setValue("USER7", as[i][15]);
                    jcotable.setValue("USER8", as[i][16]);
                    jcotable.setValue("FUNC_AREA", as[i][17]);
                    jcotable.setValue("SCOPE", as[i][18]);
                    jcotable.setValue("RD_FLAG", as[i][19]);
                    jcotable.setValue("AUFNR", as[i][20]);
                    jcofunction.execute(destination);
                    state = jcofunction.getExportParameterList().getValue("E_STATUS").toString();
                    message = jcofunction.getExportParameterList().getValue("E_MESSAGE").toString();
                }
                if ("S".equals(state)) {
                    JCoTable outtable = jcofunction.getTableParameterList().getTable("T_ITEM");
                    for (int j = 0; j < outtable.getNumRows(); j++) {
                        outtable.setRow(j);
                        retstr[j][0] = outtable.getValue("ISTAT").toString();
                        retstr[j][1] = outtable.getValue("MESSAGE").toString();
                        retstr[j][2] = outtable.getValue("AUFNR").toString();
                        logger_97683e92.error(String.valueOf("ZOA_FI_IORD_RFC:" + retstr[j][0] + "-" + retstr[j][1] + "-" + retstr[j][2]));
                    }
                } else {
                    retstr[0][0] = state;
                    retstr[0][1] = message;
                }
            }
        } catch (Exception exception) {
            retstr[0][0] = "E";
            retstr[0][1] = exception.getMessage();
        }
        return retstr;
    }
}
