<%@ language="javascript"%>
<% /*
     $Revision$
     $Id$
*/ %>
<%
    function cent(amount) {
    // returns the amount in the .99 format
        amount -= 0;
        amount = (Math.round(amount*100))/100;
        return (amount == Math.floor(amount)) ? amount + '.00' : (  (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
    }
   %>
<!--#include file="../../appl/Shared/common.inc"-->
<% FCLTHeader.Set({root: "../../appl/"}); %>
<!--#include file="../../appl/Shared/iface.inc"-->
<!-- #include file="../../appl/Shared/funcodes.inc" -->

<%
if( func_enabled[ "WEB_RELMAN"] ) {

var cid_sel = getQParamInt('cid');
var sql,oRs;
var obj_name;
%>
<html>
<head>
<%       FCLTHeader.Generate(); %>
</head>
<%

var names = new Array();
max_i=6;
i=0;
names[0] = "Tarieftype";
names[1] = L("lcl_obj_inf_room");
names[2] = L("lcl_descr");
names[3] = L("lcl_opp");
names[4] = "Tarief";
names[5] = "*Kosten";

sql  = " SELECT R.Tarieftype, R.Ruimtenr, R.omschrijving, R.gehuurdeoppervlakte Opp, R.alg_srtruimte_prijs, "
sql += "        R.gehuurdeoppervlakte * R.alg_srtruimte_prijs Kosten, R.huurder Huurder,"
sql += "        R.huurderNr HuurderNr, R.budgetcode, R.businessunit, R.cnt_contract_nummer Contractnr ";
sql += "    FROM (SELECT rg.alg_ruimte_omschrijving omschrijving,";
sql += "                 rg.alg_srtruimte_code Tarieftype,";
sql += "                 rg.alg_srtruimte_prijs,";
sql += "                 rg.alg_gebouw_upper||'-'|| TO_CHAR(rg.alg_verdieping_code)||'-'||rg.alg_ruimte_nr Ruimtenr,";
sql += "                 rg.ruimteoppervlakte,";
sql += "                 rg.gehuurdeoppervlakte,";
sql += "                 rg.Huurder,";
sql += "                 rg.HuurderNr,";
sql += "                 rg.Budgetcode Budgetcode,";
sql += "                 rg.BusinessUnit BusinessUnit,";
sql += "                 rg.cnt_contract_nummer ";
sql += "            FROM CONN_V_RUIMTEGEG rg ";
sql += "             UNION ALL ";
sql += "            SELECT rt.alg_ruimte_omschrijving omschrijving,";
sql += "                 rt.alg_srtruimte_code Tarieftype,";
sql += "                 rt.alg_srtruimte_prijs,";
sql += "                 rt.alg_gebouw_upper||'-'|| TO_CHAR(rt.alg_verdieping_code)||'-'||rt.alg_ruimte_nr Ruimtenr,";
sql += "                 rt.ruimteoppervlakte,";
sql += "                 rt.gehuurdeoppervlakte,";
sql += "                 rt.Huurder,";
sql += "                 rt.HuurderNr,";
sql += "                 rt.Budgetcode Budgetcode,";
sql += "                 rt.BusinessUnit BusinessUnit,";
sql += "                 rt.cnt_contract_nummer ";
sql += "            FROM CONN_V_TERREINGEG rt         ) R ";
sql += "      WHERE R.cnt_contract_nummer = '" + cid_sel + "'";
sql += "    ORDER BY R.Tarieftype                                                                                                                                                              "

%>
<body class="modal">

<%
oRs=Oracle.Execute(sql);
if (oRs.eof)
{
  Response.Write(L("lcl_object_not_found"));
  Response.End();
}
%>
<table id='head_table' width='100%'>
<tr><td class="label"><label>Contract:</label></td><td><%=oRs("Contractnr")%></td></tr>
<tr><td class="label"><label>Huurder:</label></td><td><%=oRs("Huurder")%></td></tr>
<tr><td class="label"><label>Debiteur:</label></td><td><%=oRs("HuurderNr")%></td></tr>
<tr><td class="label"><label>Budgetcode:</label></td><td><%=oRs("Budgetcode")%></td></tr>
<tr><td class="label"><label>Businessunit:</label></td><td><%=oRs("Businessunit")%></td></tr>
</table>
<%oRs.close();%>
<p>
    <table class='rstable' width='100%' >
         <tr><thead>
         <%
                for( i=0 ; i < max_i ; i++ ){
         %>
                        <th><%=names[i]%></th>
         <%
                }
         %>
            </thead>
         </tr>

         <%
            if( sql != "" ){
                oRs = Oracle.Execute(sql);
                var count = 0;
                var prevTar = '';
                var sumTar = 0;
                var sumTot = 0;
                while( !oRs.eof ){
         %>
         <tr>
         <%
             for( i=0 ; i < max_i ; i++ ){
                if (i==4||i==5)
                    txt=cent(oRs(i).value);
                else
                    txt=oRs(i).value;

                %><td class="nowrap" <% if (i>=3) {%>align=right<%}%>><%=txt%></td><%
             }
                 prevTar = oRs("Tarieftype").value;
                 sumTar += 0+(oRs("Kosten").value);
                 sumTot += 0+(oRs("Kosten").value);
                 oRs.MoveNext();
         %>
         </tr>
         <%
                if (oRs.eof || prevTar != oRs("Tarieftype").value)
                {
                    %>
                        <tr height=30 valign=top><td colspan=<%=max_i-1%> class="label"><label>Subtotaal <%=prevTar%></label>:</td><td align=right>&euro;&nbsp;<%=cent(sumTar)%></td></tr>
                    <%
                    sumTar = 0
                }
              }
            oRs.Close();
            }
         %>
         <tr><td colspan=<%=max_i-1%>><label>Totaal contract:</label></td><td align=right>&euro;&nbsp;<%=cent(sumTot)%></td></tr>
         </table>
    </body>
</html>
<% } else { %>
<html>
<%       FCLTHeader.Generate(); %>
<body>
<p><%=L("lcl_no_auth")%></p>
<% } %>

</body>
</html>
