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

    File:         prs_edit_bedrijf.asp
    Description:  edit bedrijf gegevens.
    Parameters:

    Context:
    Note:

*/ %>

<!-- #include file="../Shared/common.inc" -->
<!-- #include file="../Shared/iface.inc" -->
<!-- #include file="../Shared/selector.inc" -->
<!-- #include file="../Shared/kostenplaatsselector.inc" -->
<!-- #include file="../Shared/afdelingselector.inc" -->
<!-- #include file="prs_flexkenmerk.inc" -->
<!-- #include file="../Shared/calendar.inc"-->
<!-- #include file="prs.inc"-->

<%
FCLTHeader.Requires({plugins:["suggest", "jQuery", "kenmerk"]})

var bedrijf_key  = getQParamInt("bedrijf_key", -1);
if (bedrijf_key > 0)
{
  // Voor lees/schrijf autorisaties
  var sql = "SELECT prs_bedrijf_intern, prs_bedrijf_naam FROM prs_bedrijf WHERE prs_bedrijf_key = " + bedrijf_key;
  oRs = Oracle.Execute(sql);
  intern = oRs("prs_bedrijf_intern").Value == 1;
}
else
    var intern = getQParam("intern", 0) == 1;

var autfunction = "";
if (intern)
  autfunction = "WEB_PRSMAN";
else
  autfunction = "WEB_RELMAN";
var authparams = user.checkAutorisation(autfunction);

// TODO if (!authparams.canWrite) Response.End;

if (bedrijf_key > -1)
{
  var bedrijf_info = prs.prs_bedrijfinfo(bedrijf_key);
}
else
{
  var bedrijf_info = { intern: null,
                       uitvoertijd: null,
                       uitvoertijd_eenheid: null };
}
if (intern)
  bedrijf_info.intern = 1;
%>

<html>
  <head>
<%  FCLTHeader.Generate(); %>
    <script>
      function prs_submit()
      {
          document.activeElement.blur(); // trigger laatste onChanges
          if (!validateForm("u2"))
              return false;
          document.forms.u2.submit(); //TODO???
      }

      function prs_cancel()
      {
          FcltMgr.closeDetail(window, { cancel: true } );
      }

      function onChangeUitvoertijd()
      {
          if (isNaN(parseFloat($("#bdr_uitvtijd").val())))
            $("#dayshours").prop("disabled", true);
          else
            $("#dayshours").prop("disabled", false);
      }
    </script>
  </head>

  <body id="editbody">
<%  var buttons =  [ {title: L("lcl_submit"), action:"prs_submit()", icon: "opslaan.png" },
                     {title: L("lcl_cancel"), action:"prs_cancel()", icon: "undo.png" } ];
    IFRAMER_HEADER(L("lcl_ord_company"), buttons);
%>
    <div id="edit">
      <form name="u2"
            action="prs_edit_bedrijf_save.asp?bedrijf_key=<%=bedrijf_key%>"
            method="post"
            target="hidFrameSubmit"
            onSubmit="prs_submit();">
<%
        RWFIELDTR("bdr_intern",     "hidden",          "",             bedrijf_info.intern, {});

        BLOCK_START("bedrNaw", L("lcl_prs_bedrijf_nawblock"));
        RWFIELDTR("bdr_naam",     "fld",          L("lcl_prs_companies_name"),             bedrijf_info.naam, {required: true, maxlength: 60});
        RWFIELDTR("bdr_pstadr",   "fld",          L("lcl_prs_companies_post_adres"),       bedrijf_info.post_adres, {maxlength: 50});
        RWFIELDTR("bdr_pstpstc",  "fld",          L("lcl_prs_companies_post_postcode"),    bedrijf_info.post_postcode, {maxlength: 12});
        RWFIELDTR("bdr_pstpl",    "fld",          L("lcl_prs_companies_post_plaats"),      bedrijf_info.post_plaats, {maxlength: 30});
        RWFIELDTR("bdr_pstland",  "fld",          L("lcl_prs_companies_post_land"),        bedrijf_info.post_land, {maxlength: 30});
        RWFIELDTR("bdr_bezadr",   "fld",          L("lcl_prs_companies_bezoek_adres"),     bedrijf_info.bezoek_adres, {maxlength: 50});
        RWFIELDTR("bdr_bezpstc",  "fld",          L("lcl_prs_companies_bezoek_postcode"),  bedrijf_info.bezoek_postcode, {maxlength: 12});
        RWFIELDTR("bdr_bezpl",    "fld",          L("lcl_prs_companies_bezoek_plaats"),    bedrijf_info.bezoek_plaats, {maxlength: 30});
        RWFIELDTR("bdr_bezland",  "fld",          L("lcl_prs_companies_bezoek_land"),      bedrijf_info.bezoek_land, {maxlength: 30});
        BLOCK_END();

        BLOCK_START("bedrContact", L("lcl_prs_bedrijf_contactblock"));
        RWFIELDTR("bdr_tel",      "fld",          L("lcl_prs_companies_telefoon"),         bedrijf_info.telefoon, {maxlength: 20});
        RWFIELDTR("bdr_fax",      "fld",          L("lcl_prs_companies_fax"),              bedrijf_info.fax, {maxlength: 20});
        RWFIELDTR("bdr_tel2",     "fld",          L("lcl_prs_companies_telefoon2"),        bedrijf_info.telefoon2, {maxlength: 20});
        RWFIELDTR("bdr_cntper",   "fld",          L("lcl_prs_companies_contact_person"),   bedrijf_info.contact_persoon, {maxlength: 30});
        RWFIELDTR("bdr_email",    "fld",          L("lcl_prs_companies_email"),            bedrijf_info.email, {maxlength: 100});
        RWFIELDTR("bdr_cnttel",   "fld",          L("lcl_prs_companies_contact_telefoon"), bedrijf_info.contact_telefoon, {maxlength: 20});
        RWFIELDTR("bdr_cntfax",   "fld",          L("lcl_prs_companies_contact_fax"),      bedrijf_info.contact_fax, {maxlength: 20});
        CHECKBOXTR(L("lcl_prs_companies_ingids"), "fldalgbez", "bdr_ingids", bedrijf_info.ingids == 1)
        BLOCK_END();

        BLOCK_START("bedrRelatie", L("lcl_prs_bedrijf_relatieblock"));
        sql = "SELECT prs_relatietype_key"
            + "     , " + lcl.xsqla('prs_relatietype_omschrijving', 'prs_relatietype_key')
            + "  FROM prs_relatietype"
            + " WHERE prs_relatietype_verwijder IS NULL"
            + " ORDER BY 2"
        FCLTselector("prs_reltype_key", sql,
                    { label: L("lcl_prs_relatietype"),
                      initKey: bedrijf_info.prs_relatietype_key,
                      emptyOption: "",
                      readonly: false,
                      required: false
                   });
        RWFIELDTR("bdr_levnr",  "fld",              L("lcl_prs_companies_leverancier_nr"),      bedrijf_info.prs_leverancier_nr, {maxlength: 50});
        CHECKBOXTR(L("lcl_prs_companies_leverancier"), "fldalgbez", "bdr_lev", bedrijf_info.leverancier == 1);
        CHECKBOXTR(L("lcl_prs_companies_uitvoerende"), "fldalgbez", "bdr_uitv", bedrijf_info.uitvoerende == 1);
        CHECKBOXTR(L("lcl_prs_companies_contract"), "fldalgbez", "bdr_cntr", bedrijf_info.contract == 1);
        CHECKBOXTR(L("lcl_prs_companies_huurder"), "fldalgbez", "bdr_huur", bedrijf_info.huurder == 1);
        RWFIELDTR("bdr_ovknr",    "fld",               L("lcl_prs_companies_overeenkomst_nr"),  bedrijf_info.prs_overeenkomst_nr, {maxlength: 20});

        FCLTcalendar( "bdr_ovkdat",
                    { label  : L("lcl_prs_companies_overeenkomst_datum"),
                      datum  : bedrijf_info.prs_overeenkomst_datum,
                      readonly: false,
                      initEmpty: !bedrijf_info.prs_overeenkomst_datum
                    });

        RWFIELDTR("bdr_uurln",    "fldshort",          L("lcl_prs_companies_uurloon"),          bedrijf_info.uurloon, {maxlength: 7});
        RWFIELDTR("bdr_beslim",   "fldshort",          L("lcl_prs_companies_bes_limiet"),       bedrijf_info.bes_limiet, {maxlength: 10, datatype: "float"});
        RWFIELDTR("bdr_beskst",   "fldshort",          L("lcl_prs_companies_bes_kosten"),       bedrijf_info.bes_kosten, {maxlength: 10, datatype: "float"});
        RWTEXTAREATR("bdr_opm", "fldtxt", L("lcl_prs_companies_opmerking"), bedrijf_info.opmerking, {html: "maxlength='320'"});
        RWTEXTAREATR("bdr_opm2", "fldtxt", L("lcl_prs_companies_opmerking2"), bedrijf_info.opmerking2, {html: "maxlength='320'"});

        sql = "SELECT mld_adres_key"
            + "     , mld_adres_naam"
            + "  FROM mld_v_aanwezigadres"
            + " WHERE mld_adres_afleveradres = 1"
            + " ORDER BY 2"

        FCLTselector("mld_adrlkey", sql,
                    { label: L("lcl_prs_companies_adres_lev"),
                      initKey: bedrijf_info.mld_adres_key_lev,
                      emptyOption: "",
                      readonly: false,
                      required: false
                   });

        sql = "SELECT mld_adres_key"
            + "     , mld_adres_naam"
            + "  FROM mld_v_aanwezigadres"
            + " WHERE mld_adres_factuuradres = 1"
            + " ORDER BY 2"

        FCLTselector("mld_adrfkey", sql,
                    { label: L("lcl_prs_companies_adres_fac"),
                      initKey: bedrijf_info.mld_adres_key_fac,
                      emptyOption: "",
                      readonly: false
                   });
        sql = "SELECT fin_btwtabel_key"
            + "     , fin_btwtabel_omschrijving"
            + "  FROM fin_btwtabel"
            + " WHERE fin_btwtabel_verwijder is NULL"
            + " ORDER BY fin_btwtabel_default DESC, 2"

        FCLTselector("finbtwtabelkey", sql,
                    { label: L("lcl_fin_btwtabel"),
                      initKey: bedrijf_info.fin_btwtabel_key,
                      emptyOption: ""
                   });
        BLOCK_END();
        // Of verstoppen achter een action-button?
        if( user.checkAutorisation("WEB_PRSSYS", true) || user.checkAutorisation("WEB_PRSMGT", true))
        {
          BLOCK_START("bedrTechn", L("lcl_prs_bedrijf_techblock"));
          RWFIELDTR("bdr_imgloc",  "fld",          L("lcl_prs_companies_image_loc"),          bedrijf_info.image_loc, {maxlength: 256});
          RWFIELDTR("bdr_detloc",  "fld",          L("lcl_prs_companies_details_loc"),        bedrijf_info.details_loc, {maxlength: 256});
          RWFIELDTR("bdr_xmldetl", "fld",          L("lcl_prs_companies_xmldetails_loc"),     bedrijf_info.xmldetails_loc, {maxlength: 256});
          RWFIELDTR("bdr_xmlcatl", "fld",          L("lcl_prs_companies_xmlcatalogus_loc"),   bedrijf_info.xmlcatalogus_loc, {maxlength: 256});
          RWCHECKBOXTR("bdr_confirm", "fldalgbez", L("lcl_prs_companies_order_confirm"),      bedrijf_info.order_confir == 1);
          sql = "SELECT  'U', " + safe.quoted_sql(L("lcl_mld_hours")) + " FROM DUAL"
              + " UNION SELECT  'D', " + safe.quoted_sql(L("lcl_mld_days")) + " FROM DUAL"
              + " ORDER BY 2";
          var selectparams = { fieldName: "dayshours",
                               sql: sql,
                               params: { initKey: bedrijf_info.uitvoertijd_eenheid,
                                         disable: !bedrijf_info.uitvoertijd }
                             }
          //selectparams.params.initKey = bedrijf_info.uitvoertijd_eenheid;
          RWFIELDTR("bdr_uitvtijd", "fldbdr_uitvtijd", L("lcl_prs_uitvoertijd"), bedrijf_info.uitvoertijd? Math.round(bedrijf_info.uitvoertijd * 100) / 100 : "", {maxlength: 4, datatype: "float", html: "onChange='onChangeUitvoertijd();'", selector: selectparams});
          BLOCK_END();
        }

        BLOCK_START("prsFlex"+(S("prs_flexcolumns")!=1?"2":""), L("lcl_prs_bedrijf_flexblock"));
          generateFlexKenmerkCode ({ link_key: bedrijf_key,
                                     niveau: "B",
                                     reado: false,
                                     flexcolumns: S("prs_flexcolumns")
                                   });
        BLOCK_END();
        IFACE.FORM_END();
%>
      </form>
      <iframe src="../Shared/empty.html" name="hidFrameSubmit" style="display:none"></iframe>
    </div>
  </body>
</html>
