<%@ language = "JavaScript" %>
<% /*
     $Revision$
     $Id$

    File:        pda/cnt_list.asp
    Description: Toont een beknopte contractenlijst voor op de pda, dat zijn de aan mij toegekende (beheerder of contact) contracten
                 Hiervoor heb ik verder geen aanvullende autorisatie nodig.

    Parameters:  -
    Context:     -

    Note:        Wellicht tzt met volledige autorisatie/scope e.d, maar eerst maar eens zo
*/
%>
<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/discx3d.inc" -->
<!-- #include file="./resultset_table.inc" -->
<!-- #include file="./mobile.inc" -->
<!-- #include file="./iface.inc" -->

<%
var grp_sel = getQParam("grp", "");
var qrc = getQParamInt("qrc", 0) != 0;
var subject = L("lcl_mobile_contracten");

%>
<html><head>
<% FCLTMHeader.Generate({}); %>
</head><body>
<%
function fncolLink(oRs)
{
    var url = "";
    if (grp_sel == "")
      url = "../pda/cnt_list.asp?grp=" + safe.url(oRs("ins_discipline_omschrijving").Value);
    else
      url = "../pda/contract.asp?cnt_key=" + oRs("cnt_contract_key").Value;
    return url;
};
function fnHeader (oRs) {
    return oRs("cnt_contract_nummer_intern").value + (oRs("cnt_contract_versie").value == null ? "" : "."+oRs("cnt_contract_versie").value);
}
function fnBedrag (oRs) {
    return oRs("cnt_contract_kosten").value ? S("currency_pref")+safe.curr(oRs("cnt_contract_kosten").value) : "";
}
function fncolSubHeader(oRs) {
    return  "<div class='listbodykop'>" + toDateString(oRs("begindatum").value, true) + " " + L("lcl_tot") + " " + toDateString(oRs("einddatum").value, true) +"</div>"
            + (oRs("cnt_contract_omschrijving").Value? "<div class='listbodytext'>" +safe.html(shorttxt(oRs("cnt_contract_omschrijving").Value, S("rs_mobile_maxchar")))+"</div>":"");
};

function fnEinddatum (oRs) {
    return toDateString(oRs("einddatum").value, false);
}
    sql = "SELECT   c.cnt_contract_key"
          + "     , " + lcl.xsqla('cd.ins_discipline_omschrijving','cd.ins_discipline_key')
          + "     , c.cnt_contract_nummer_intern"
          + "     , c.cnt_contract_versie"
          + "     , c.cnt_contract_omschrijving"
          + "     , COALESCE(b.prs_bedrijf_naam, " + S("prs_dep_string") + ", " + S("prs_pers_string") + ") uitvoerder"
          + "     , c.cnt_contract_looptijd_van begindatum"
          + "     , c.cnt_contract_looptijd_tot einddatum"
          + "     , c.cnt_contract_status"
          + "     , c.cnt_contract_kosten"
          + "  FROM prs_bedrijf b"
          + "     , cnt_v_aanwezigcontract c"
          + "     , prs_v_afdeling d"
          + "     , prs_perslid p"
          + "     , cnt_discipline cd"
          + " WHERE b.prs_bedrijf_key(+) = c.cnt_prs_bedrijf_key"
          + " AND c.cnt_prs_afdeling_key = d.prs_afdeling_key(+)"
          + " AND c.cnt_prs_perslid_key = p.prs_perslid_key(+)"
          + " AND c.ins_discipline_key = cd.ins_discipline_key"
          + " AND (c.prs_perslid_key_beh = " + user_key
          + "     OR c.prs_perslid_key_eig = " + user_key + ")"
          + " AND c.cnt_contract_status = 0"
// toekomstig ook          + " AND c.cnt_contract_looptijd_van <= SYSDATE"
          + " AND c.cnt_contract_looptijd_tot >= SYSDATE";
    sql = "SELECT * FROM (" + sql + ")"
          + (grp_sel==""
            ? ""
            : " WHERE ins_discipline_omschrijving = " + safe.quoted_sql(grp_sel)
          )
          + " ORDER BY ins_discipline_omschrijving, uitvoerder, cnt_contract_omschrijving, cnt_contract_nummer_intern";


    PAGE_START();
    HEADER({title: subject, back:!qrc});
    CONTENT_START();
    var rst = new ResultsetTable({sql: sql,
                                   keyColumn: "cnt_contract_key",
                                   detailColumn: "uitvoerder",
                                   headerColumn: fnHeader,
                                   asideColumn: fnBedrag,
                                   subheaderColumn: fncolSubHeader,
                                   groupColumn: "ins_discipline_omschrijving",
                                   groupSelect: grp_sel,
                                   linkColumn: fncolLink,
                                   ID: "cnttable",
                                   showAll: true
                                  });

    var cnt = rst.processResultset();

    CONTENT_END();
    FOOTER();
    PAGE_END();
%>
  </body>
</html>
