<%@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.text.SimpleDateFormat,
 java.util.Date,
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 workordersArray=new JSONArray();
    JSONObject jsonWOS = new JSONObject();
    if (talPlanif != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm"); 
        JSONObject jsonFIN = new JSONObject();
        String wo_wc = "rownum<2";
        if (!talPlanif.isNull("TAL_WO_WC"))
            wo_wc = talPlanif.getString("TAL_WO_WC");
        wo_wc = wo_wc;
        MboSetRemote WoRemoteSet = mxServer.getMboSet("TAL_WORKORDER",userInfo);
        WoRemoteSet.setWhere(wo_wc);
        MboRemote WoRemote = null;
        MboRemote assignRemote = null;

        MboSetRemote assignRemoteSet = mxServer.getMboSet("TAL_ASSIGNMENT",userInfo);

        for (int i = 0; ((WoRemote = WoRemoteSet.getMbo(i))) != null; i++) {
            WoRemoteSet.setWhere("wonum = '"+ WoRemote.getString("WONUM") +"'");
            for(int j = 0 ; ((assignRemote = assignRemoteSet.getMbo(j)))!= null; j++ )
            {               
                JSONObject jsonWO = new JSONObject(); 
                jsonWO.put("CRAFT", assignRemote.getString("CRAFT"));
                jsonWO.put("WONUM", assignRemote.getString("WONUM"));
                workordersArray.add(jsonWO);
            }
        }
    }
    retour = workordersArray.toString();
} catch (Exception e) {
    out.println("Erreur serveur: " + e.getMessage());
    e.printStackTrace();
}
%><%=retour%>
