<%@ LANGUAGE="JavaScript" %> <% /* $Revision$ $Id$ File: bes_retour.asp Description: Retour van een bestelling door middel van negatieve aantallen Parameters: bes_key Bestelaanvraag nummer (key) submitting 0 = invoer opmerking, 1 = reject mode opmerk Opmerking */ %> <% FCLTHeader.Requires({ plugins: ["jQuery"], js: ["num2curr.js"] }); var bes_key = getQParamInt("bes_key"); var bes_bestelling = bes.bestelling_info(bes_key); // Globale variabele met alle bes_bestelling informatie var bes_disc_info = bes.disc_info(bes_bestelling.dis_key); // alle discipline informatie var count = 0; var authparams = user.checkAutorisation(["WEB_BESUSE", "WEB_BESFOF"]); // Autorisatie is afhankelijk van beide bes functies var this_bes = bes.func_enabled_bestelling(bes_bestelling); user.auth_required_or_abort(this_bes.canRetourBES); %>
<% FCLTHeader.Generate(); %>
<% var submitting = getQParamInt("submit", 0) == 1; if (submitting) { protectRequest.validateToken(); // Sla de ingevoerde gegevens op in een nieuwe bestellingsaanvraag var deliveryAddr = getFParam('deliveryAddr'); newremark = getFParam("remark", ""); delivery_place = getFParam("delivery_place", ""); oRs = Oracle.Execute("SELECT bes_s_bes_bestelling_key.nextval FROM DUAL"); new_bes_key = oRs(0).Value; oRs.close(); sql = " INSERT INTO bes_bestelling (" + " bes_bestelling_key, " + " bes_bestelling_module" + ", bes_bestelling_status" + ", bes_bestelling_datum" + ", prs_perslid_key" + ", bes_bestelling_opmerking" + ", bes_bestelling_ordernr" + ", bes_bestelling_plaats" + ", bes_bestelling_fiat_user" + ", mld_adres_key_lev" + ", prs_kostenplaats_key" + ", fac_activiteit_key" + ", bes_bestelling_leverdatum" + ", bes_bestelling_kosten_klant" + ", bes_bestelling_retourvan_key)" + " SELECT " + new_bes_key + ", " + " bes_bestelling_module" + ", 2" // default waarde + ", SYSDATE" + ", prs_perslid_key" + ", " + safe.quoted_sql(newremark, 320) + ", bes_bestelling_ordernr" + ", " + safe.quoted_sql(delivery_place) + ", bes_bestelling_fiat_user" + ", " + deliveryAddr + ", prs_kostenplaats_key" + ", fac_activiteit_key" + ", bes_bestelling_leverdatum" + ", bes_bestelling_kosten_klant" + ", " + bes_key + " FROM bes_bestelling" + " WHERE bes_bestelling_key = " + bes_key; oRs = Oracle.Execute(sql); // kopieer de bestelitemkenmerken van de orginele bestelitems sql = "INSERT INTO bes_kenmerkbestell" + " (bes_bestelling_key" + ", bes_kenmerk_key" + ", bes_kenmerkbestell_waarde" + ", bes_kenmerkbestell_aanmaak)" + " SELECT " + new_bes_key + ", bes_kenmerk_key" + ", bes_kenmerkbestell_waarde" + ", SYSDATE" + " FROM bes_kenmerkbestell" + " WHERE bes_bestelling_key = " + bes_key; Oracle.Execute(sql); max_o_i = getFParamInt('max_o_i'); for (i = 0; i < max_o_i; i++) { retour = getFParamInt('cnt'+i, 0, true); // ingevulde aantal, relaxed check bokey = getFParamInt('bokey'+i); // boi.bes_bestelopdr_item_key bikey = getFParamInt('bi_key'+i); // bes_bestelling_item_key if (retour != 0) { oRs = Oracle.Execute("SELECT bes_s_bes_bestelling_item_key.nextval FROM DUAL"); new_bikey = oRs(0).Value; oRs.close(); sql = "INSERT INTO bes_bestelling_item (" + "bes_bestelling_item_key, " + " bes_bestelling_key" + ", bes_srtdeel_key" + ", bes_bestelling_item_prijs" + ", bes_bestelling_item_brutoprijs" + ", bes_bestelling_item_aantal" + ", bes_bestelling_item_status)" + " SELECT " + new_bikey + ", " + new_bes_key + ", bes_srtdeel_key" + ", bes_bestelling_item_prijs" + ", bes_bestelling_item_brutoprijs" + ", -" + retour + ", 2" + " FROM bes_bestelling_item" + " WHERE bes_bestelling_key = " + bes_key + " AND bes_bestelling_item_key = " + bikey; Oracle.Execute(sql); // kopieer de bestelitemkenmerken van de orginele bestelitems sql = "INSERT INTO bes_kenmerkbesteli" + " (bes_bestelling_item_key" + ", bes_kenmerk_key" + ", bes_kenmerkbesteli_waarde" + ", bes_kenmerkbesteli_aanmaak)" + " SELECT " + new_bikey + ", bes_kenmerk_key" + ", bes_kenmerkbesteli_waarde" + ", SYSDATE" + " FROM bes_kenmerkbesteli" + " WHERE bes_bestelling_item_key = " + bikey; Oracle.Execute(sql); } } // Indien BO niet hoeft te fiatteren kan de bestelling direct geaccepteerd worden if (S("bes_retour_need_approval") == 0) { // bestelling naar status geaccepteerd (4) bes.setbestellingstatus(new_bes_key, 4); // Gefiatteerd if (bes_disc_info.disc_params_auto_order == "1") { // automatisch opdracht staat aan? bes.makeOrders(user_key, new_bes_key); // automatisch opdracht aanmaken en status naar besteld (5) } } else { // BO moet bestelling accepteren, status gefiatteerd (3) bes.setbestellingstatus(new_bes_key, 3); // Te accepteren door BO } %>
<% Response.End; } // Maak het retourformulier %> <% BLOCK_START("besretour" , L("lcl_bes_aanvragergegevens")); sql = "SELECT DISTINCT b.bes_bestelopdr_key," + " bd.prs_bedrijf_naam," + lcl.xsqla('s.bes_srtdeel_omschrijving','s.bes_srtdeel_key') +", " + " COALESCE("+ lcl.xsql('s.bes_srtdeel_eenheid','s.bes_srtdeel_key') +",'') isd_eenheid, " + " COALESCE(boi.bes_bestelopdr_item_prijs,0) boi_price," + " bi.bes_bestelling_item_key," + " boi.bes_bestelopdr_item_aantal boi_aantal," + " COALESCE(boi.bes_bestelopdr_item_aantalontv,0) boi_ontv," + " m.mld_adres_bezoek_adres ||" + "' '|| m.mld_adres_bezoek_postcode " + "||' '||" + " m.mld_adres_bezoek_plaats d_place, " + " b.bes_bestelopdr_opmerking oremark," + " boi.bes_bestelopdr_item_key boi_key," + " s.bes_srtdeel_nr catstr," + " b.bes_bestelopdr_delivery_opmerk odelremark," + " ABS((SELECT SUM (bi2.bes_bestelling_item_aantal)" + " FROM bes_bestelling_item bi2" + " WHERE bi2.bes_bestelling_key IN (" + " SELECT bes_bestelling_key" + " FROM bes_bestelling" + " WHERE bes_bestelling_retourvan_key = " + bes_key + ")" + " AND bi2.bes_srtdeel_key = bi.bes_srtdeel_key" + " GROUP BY bes_srtdeel_key)) retour" + ", m.mld_adres_key" + " FROM ins_tab_discipline d" + ", bes_srtgroep g" + ", bes_srtdeel s" + ", prs_bedrijf bd" + ", bes_bestelopdr b" + ", mld_adres m" + ", bes_bestelling_item bi" + ", bes_bestelopdr_item boi" + ", bes_bestelling bes" + " WHERE d.ins_discipline_key = g.ins_discipline_key" // PF: hier waren nog wat secundaire condities; nu verwijderd. + " AND g.bes_srtgroep_key = s.bes_srtgroep_key" + " AND s.bes_srtdeel_key = bi.bes_srtdeel_key" + " AND bi.bes_bestelling_key = bes.bes_bestelling_key" + " AND b.bes_bestelopdr_key = boi.bes_bestelopdr_key" + " AND bi.bes_bestelopdr_item_key = boi.bes_bestelopdr_item_key" + " AND b.prs_bedrijf_key = bd.prs_bedrijf_key" + " AND m.mld_adres_key(+)= b.mld_adres_key_lev" //+ " AND b.bes_bestelopdr_key = " + ordernr + " AND bi.bes_bestelling_key = " + bes_key + " ORDER BY s.bes_srtdeel_nr"; oRs = Oracle.Execute(sql); d_place = oRs("d_place").value; mld_adres_key = oRs("mld_adres_key").value; oremark = oRs("oremark").value; odelremark = oRs("odelremark").value; okey = oRs("bes_bestelopdr_key").value; ROFIELD("fld", L("lcl_bes_Supplier"), oRs("prs_bedrijf_naam").value); RWTEXTAREATR("remark", "fldtxt required", L("lcl_bes_retour_remark"), odelremark, {html: "rows='3' cols='30' onkeypress='guardMaxLength(event);' onpropertychange='ensureMaxLength(event);' maxlength='320'"}); %> <% sqlD = "SELECT m.mld_adres_key" + ", m.mld_adres_naam, m.mld_adres_upper" + " FROM mld_v_afleveradres m" + (authparams.ALGreadlevel >= 0 ? " WHERE m.alg_locatie_key IN (SELECT alg_locatie_key FROM fac_v_my_locations " + " WHERE prs_perslid_key = " + user_key + " AND niveau = " + authparams.ALGreadlevel + ")" : "") + (bes_bestelling.bes_key > 0 // Huidige waarde ook toevoegen aan lijst ? " UNION" + " SELECT m.mld_adres_key" + " , m.mld_adres_naam" + " , m.mld_adres_upper" + " FROM mld_v_afleveradres m" + " WHERE m.mld_adres_key = " + bes_bestelling.mld_adres_key : "") + " ORDER BY mld_adres_upper", FCLTselector("deliveryAddr", sqlD, { label: L("lcl_delivery_address"), emptyOption: "", initKey: mld_adres_key, onChange: "document.forms.u2.delivery_place.value = \"\";", required: true } ); %>
<%=L("lcl_bes_del_room")%>:
<% BLOCK_END() BLOCK_START("besRetourItems" , L("lcl_bes_geselecteerd")); function fncolArtikel(oRs) { var fitemstr = oRs("bes_srtdeel_omschrijving").value + " (" + S("currency_pref") + safe.curr(oRs("boi_price").value) + S("currency_suff") + "/" + oRs("isd_eenheid").value + ")"; return safe.html(fitemstr); } function fncolRetourSoFar(oRs) { var retour = oRs("retour").value; if (retour && retour != -1) return retour; else return 0; } function fncolRetour(oRs) { retour = "" + "" // boi.bes_bestelopdr_item_key + ""; // bes_bestelling_item_key return retour; } function fncolRemaining(oRs) { var retour = oRs("retour").value; var ordered = oRs("boi_aantal").value; if (retour && retour != -1) var remaining = ordered - retour; else var remaining = ordered; remaining = remaining + ""; // bes_bestelopdr_item_aantal - bes_bestelopdr_item_aantalontv count++; return remaining; } var rst = new ResultsetTable({keyColumn: "bes_bestelopdr_key", ID: "bestable", sql: sql, noPrint: true, outputmode: 0, title: L("lcl_bes_bestellingen"), showAll: true }); // Kolommen rst.addColumn(new Column({caption: L("lcl_bes_srtdeel_nr"), content: "catstr"})); rst.addColumn(new Column({caption: L("lcl_bes_srtdeel"), content: fncolArtikel})); rst.addColumn(new Column({caption: L("lcl_bes_ordered"), content: "boi_aantal", datatype: "number"})); rst.addColumn(new Column({caption: L("lcl_bes_retour_so_far"), content: fncolRetourSoFar, datatype: "number"})); rst.addColumn(new Column({caption: L("lcl_bes_retour"), content: fncolRetour})); rst.addColumn(new Column({caption: L("lcl_bes_retour_remaining"), content: fncolRemaining, datatype: "number"})); var count = rst.processResultset(); %> <% BLOCK_END() var buttons = [{title: L("lcl_submit"), icon: "opslaan.png", action: "doSubmit()", singlepress: true, id: "btn_retour_submit"}, {title: L("lcl_cancel"), icon: "undo.png", action:"FcltMgr.closeDetail(window, {cancel: true});" } ]; CreateButtons(buttons); IFACE.FORM_END(); %>