<%@page contentType="text/html;charset=UTF-8" autoFlush="true"%>
<%@page contentType="text/html;charset=UTF-8" autoFlush="true"%>
<%@page import="psdi.webclient.system.controller.*,psdi.webclient.system.beans.*, psdi.mbo.*, java.io.*,
 com.ibm.json.java.JSONArray,
 com.ibm.json.java.JSONObject,
 java.lang.Exception,
 psdi.webclient.system.session.*,
 psdi.server.MXServer,
 psdi.security.UserInfo,
java.util.Calendar,
 java.lang.*"%>


<%

String retour = "";
try {
    // get main record id
	int talPlanifId = Integer.parseInt(request.getParameter("talPlanifId"));
	
	// get mboSet for main object
	MXServer mxServer = MXServer.getMXServer();
	UserInfo userInfo = mxServer.getSystemUserInfo();

	MboSetRemote	talPlanifSet = mxServer.getMboSet("TAL_PLANIF",userInfo);
	talPlanifSet.setWhere("TAL_PLANIFID="+talPlanifId);
	MboRemote		talPlanif	= talPlanifSet.getMbo(0);

    JSONArray laborsArray=new JSONArray();
    JSONObject jsonLABORS = new JSONObject();
    if(talPlanif!=null)
    {
        JSONObject jsonFIN = new JSONObject();
        String labor_wc = "LABORCODE IS NOT NULL";
        if(!talPlanif.isNull("TAL_LABCRAFTRATE_WC"))
            labor_wc = talPlanif.getString("TAL_LABCRAFTRATE_WC");
        MboSetRemote laborset = mxServer.getMboSet("LABOR",userInfo);
        laborset.setWhere(labor_wc);
        MboRemote labor=null;

            for(int i = 0; ((labor=laborset.getMbo(i)))!=null; i++)
            {
                // get LABORs
                JSONObject jsonLABOR = new JSONObject();
                jsonLABOR.put("ORGID",labor.getString("ORGID"));
                jsonLABOR.put("LABORID",labor.getInt("LABORID"));
                jsonLABOR.put("LABORCODE",labor.getString("LABORCODE"));
                jsonLABOR.put("DISPLAYNAME",labor.getString("PERSON.DISPLAYNAME"));

                String CRAFT = labor.getString("LABORCRAFTRATE.CRAFT");
                if(CRAFT != null && !CRAFT.isEmpty())
                    jsonLABOR.put("CRAFT",CRAFT);

                String CALNUM = labor.getString("CALNUM");
                if(CALNUM != null && !CALNUM.isEmpty())
                    jsonLABOR.put("CALNUM",CALNUM);

                String SHIFTNUM = labor.getString("SHIFTNUM");
                if(SHIFTNUM != null && !SHIFTNUM.isEmpty())
                    jsonLABOR.put("SHIFTNUM",SHIFTNUM);

                String WORKSITE = labor.getString("WORKSITE");
                if(WORKSITE != null && !WORKSITE.isEmpty())
                    jsonLABOR.put("WORKSITE",WORKSITE);

                laborsArray.add(jsonLABOR);
            }
    } retour =   laborsArray.toString();
} catch (Exception e) {
out.println("Erreur serveur: " + e.getMessage());
e.printStackTrace();
}
%><%=retour%>