var URLdestination = 0 //0 Gephymat, 1 Supervision, 2 Consolidation, 3 Message....
var DoubleClickEnCours = false;
function escapeHtml(html) {
var text = document.createTextNode(html);
var div = document.createElement('div');
div.appendChild(text);
return div.innerHTML;
}
// Permet d'envoyer un ScreenShot et d'appeller le support
function getSupport() {
$.ajax({
type: 'POST',
url: '/Shared/getCwSupport',
async: true,
success: function (res) {
$('#Window').html(res);
stopLoading();
CenterCW("cwSupport");
}
})
};
$.fn.serializeObject = function () {
var o = {};
var a = this.serializeArray();
$.each(a, function () {
if (o[this.name] !== undefined) {
if (!o[this.name].push) {
o[this.name] = [o[this.name]];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
};
function loading(onTop) {
try {
var url = '/Shared/GetcwLoading';
if ($('#WindowLoading').html() == "") {
$.ajax({
type: "POST",
url: url,
async: false,
success:
function (res) {
$('#WindowLoading').html(res);
if (onTop != "false") {
window.scrollTo(1, 0);
}
var position = 150 + window.pageYOffset;
if (!$("#isAdminMobile").val() || $("#isAdminMobile").val() == "false") {
position += 150;
}
$("#cwLoading").data("kendoWindow").center();
$("#cwLoading").data("kendoWindow").element.parent().css({ top: position });
//$("#cwLoading").data("kendoWindow").center();
$("#cwLoading").data("kendoWindow").open();
$("#cwLoading").css("overflow", "hidden");
if ($("#isAdminMobile").val() && $("#isAdminMobile").val() == "true") {
$("#cwLoading").data("kendoWindow").center();
if ($(".menu").length > 0) {
$("#cwLoading").data("kendoWindow").element.parent().css({ left: $(".menu").first().width() / 2, transform: "translateX(-50%)" });
}
}
}
});
}
else {
var position = 150 + window.pageYOffset;
if (!$("#isAdminMobile").val() || $("#isAdminMobile").val() == "false") {
position += 150;
}
$("#cwLoading").data("kendoWindow").center();
$("#cwLoading").data("kendoWindow").element.parent().css({ top: position });
//$("#cwLoading").data("kendoWindow").center();
$("#cwLoading").data("kendoWindow").open();
$("#cwLoading").css("overflow", "hidden");
if ($("#isAdminMobile").val() && $("#isAdminMobile").val() == "true") {
$("#cwLoading").data("kendoWindow").center();
if ($(".menu").length > 0) {
$("#cwLoading").data("kendoWindow").element.parent().css({ left: $(".menu").first().width() / 2, transform: "translateX(-50%)" });
}
}
}
}
catch (e) {
console.log(e);
}
}
function stopLoading() {
try {
$("#cwLoading").data("kendoWindow").close();
} catch (e) {
console.log(e);
}
}
function onClose_ucChildWindow() {
$("#ucChildWindow").data("kendoWindow").destroy();
}
function onClose_ucChildWindowSansTitre() {
$("#ucChildWindowSansTitre").data("kendoWindow").destroy();
$("#Window").html("");
}
// A Utiliser pour bien conserver la session quand veut charger une page
function Redirect(pUrl) {
var link = "/";
if (pUrl.startsWith("/")) {
link = "";
}
window.location.href = window.location.origin + "/" + window.location.pathname.split("/")[1] + link + pUrl;
return false;
}
function CheckSession() {
$.ajax({
type: "POST",
url: "/Shared/CheckSession",
async: true,
success:
function (res) {
if (res != "") {
Redirect(res);
}
}
});
}
/*------------------------*/
// Login //
/*------------------------*/
function valideLogin(typeLogin) {
loading();
var tactile = false;
if (isTouchDevice()) {
tactile = true;
$("body").addClass("tactile");
}
$.ajax({
type: "POST",
url: "/Home/valideLogin",
data: { pLogin: $("#txtLogin").val(), pPassword: $("#txtPassword").val(), SeSouvenir: $("#chkSouvenir").is(":checked"), pTactile: tactile, pTypeLogin: typeLogin },
async: true,
success:
function (res) {
if (res.indexOf("203") > -1) {
Redirect("Admin");
}
else if (res.indexOf("200") > -1) {
Redirect("Gephymat");
}
else if (res.indexOf("201") > -1) {
Redirect("PriceManager");
}
else if (res.indexOf("202") > -1) {
Redirect("Gephysio");
}
else {
$("#divLoginMsg").html(res);
stopLoading();
}
}
});
}
function oubliMotDePasseClick() {
$.ajax({
type: "POST",
url: '/Home/ShowCwOubliPwd',
async: true,
success:
function (res) {
$('#Window').contents().remove();
$('#Window').html(res);
CenterCW("cwOubliPwd");
}
});
}
/*-----------------------*/
// Filtre Production //
//-----------------------*/
function getFiltreProduction() {
$.ajax({
type: "POST",
url: "/Shared/getucFiltreProduction",
async: true,
success:
function (res) {
$('#FiltreProduction').html(res);
getOnglet();
}
});
}
function InitPositionFiltreProduction()
{
// AB le 23/05/18 : je sais pas pourquoi mais subitement la position top de divcontent est très grande
// en attendant un tout petit peu on retombe à la valeur normale
// ==> on met une petite attente avant d'affecter la position du filtre sinon il se retrouve beaucoup trop bas.
setTimeout(function () { $("#FiltreProduction").css("top", ($("#divContent").position().top + 20) + "px") }, 100);
}
function SaveParam(pCod, pVal) {
$.ajax({
type: "POST",
url: "/Shared/SaveParam",
data: { pCod: pCod, pVal: pVal },
async: true,
dataType: "html",
success:
function (res) {
//SUCCESS ne rien faire
}
});
}
function SaveVarSession(pVarSession, pVal) {
$.ajax({
type: "POST",
url: "/Shared/SaveVarSession",
data: { pVarSession: pVarSession, pVal: pVal },
async: false,
dataType: "html"
});
}
function IntegerBox(evt) {
var theEvent = evt || window.event;
// on regarde si la touche pressée n'est pas une fleche, un backspace, une tab ou un suppr
if (theEvent.keyCode != 8 &&
theEvent.keyCode != 9 &&
theEvent.keyCode != 37 &&
theEvent.keyCode != 38 &&
theEvent.keyCode != 39 &&
theEvent.keyCode != 40 &&
theEvent.keyCode != 46) {
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[-0-9]/;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
}
function AllowDecimal(evt) {
var theEvent = evt || window.event;
// on regarde si la touche pressée n'est pas une fleche, un backspace, une tab ou un suppr
if (theEvent.keyCode != 8 &&
theEvent.keyCode != 9 &&
theEvent.keyCode != 37 &&
theEvent.keyCode != 38 &&
theEvent.keyCode != 39 &&
theEvent.keyCode != 40 &&
theEvent.keyCode != 46) {
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[0-9]|\./;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
}
function DecimalBox(evt, pInput, pNbDecimal) {
var theEvent = evt || window.event;
// on regarde si la touche pressée n'est pas une fleche, un backspace, une tab ou un suppr
if (theEvent.keyCode != 8 &&
theEvent.keyCode != 9 &&
theEvent.keyCode != 37 &&
theEvent.keyCode != 38 &&
theEvent.keyCode != 39 &&
theEvent.keyCode != 40 &&
theEvent.keyCode != 46) {
var key = theEvent.keyCode || theEvent.which;
key = String.fromCharCode(key);
var regex = /[0-9]|\./;
if (!regex.test(key)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
else {
// on controle le format du champs
var newInput = pInput.value;
switch (pNbDecimal) {
case 0: regex = /^[0-9]+$/;
break;
case 1: regex = /^[0-9]+[\.]{0,1}[0-9]{0,1}$/;
break;
case 2: regex = /^[0-9]+[\.]{0,1}[0-9]{0,2}$/;
break;
case 3: regex = /^[0-9]+[\.]{0,1}[0-9]{0,3}$/;
break;
case 4: regex = /^[0-9]+[\.]{0,1}[0-9]{0,4}$/;
break;
default: regex = /^[0-9]+[\.]{0,1}[0-9]{0,2}$/;
break;
}
if (!regex.test(newInput)) {
theEvent.returnValue = false;
if (theEvent.preventDefault) theEvent.preventDefault();
}
}
}
}
var Icone = {
Infos: "Infos",
WarningJaune: "WarningJaune",
WarningOrange: "WarningOrange",
Error: "Error",
Alarm: "Alarm"
};
/*pIcone : Icone est une classe de style enum, elle contient la liste des icones possibles*/
function MsgBoxAlert(pTitre, pMessage, pIcone) {
$.ajax({
type: "POST",
url: '/Shared/MsgBoxAlert',
data: { pTitre: pTitre, pMessage: pMessage, pIcone: pIcone },
async: true,
success:
function (res) {
$('#WindowMsgBoxAlert').contents().remove();
$('#WindowMsgBoxAlert').html(res);
CenterCW("cwMsgBoxAlert");
//$("#cwMsgBoxAlert").data("kendoWindow").center();
}
});
}
/*Détection du tactile*/
function isTouchDevice() {
//JMAHU only for the debug
return false;
//if ($(".k-ie").length == 0) {
// return !!('ontouchstart' in window) // Autres browsers
// || !!('onmsgesturechange' in window); // IE10
//}
//else {
// return window.navigator.msMaxTouchPoints > 0
//}
};
function CenterCW(pCwName) {
//évite que IE ne place la window en bas de la page
window.scrollTo(1, 0);
//---------------------------
var position = 40 + window.pageYOffset;
$("#" + pCwName).data("kendoWindow").center();
$("#" + pCwName).data("kendoWindow").element.parent().css({ top: position });
$("#" + pCwName).data("kendoWindow").open();
}
/*--------------Export excel --------------*/
(function ($) {
var kendo = window.kendo;
var ExcelGrid = kendo.ui.Grid.extend({
init: function (element, options) {
var that = this;
if (options.excel) {
options.excel = $.extend(
{
cssClass: "k-i-expand" // If the exportCssClass is not defined, then set a default image.
},
options.excel);
// Add the export toolbar button.
options.toolbar = $.merge([
{
name: "export",
template: kendo.format("Export", options.excel.cssClass)
}
], options.toolbar || []);
}
// Initialize the grid.
kendo.ui.Grid.fn.init.call(that, element, options);
// Add an event handler for the Export button.
/*$(element).on("click", ".k-grid-export", { sender: that }, function (e) {
e.data.sender.exportToExcel();
});*/
$(".BtExcel").click({ sender: that }, function (e) {
e.data.sender.exportToExcel();
});
},
options: {
name: "ExcelGrid"
},
exportToExcel: function () {
var that = this;
// Create a datasource for the export data.
var ds = new kendo.data.DataSource({
data: that.dataSource.data()
});
ds.query({
aggregate: that.dataSource._aggregate,
filter: that.dataSource._filter,
sort: that.dataSource._sort
});
// Define the data to be sent to the server to create the spreadsheet.
data = {
model: JSON.stringify(that.columns),
data: JSON.stringify(ds._view),
title: that.options.excel.title
};
// Create the spreadsheet.
$.ajax({
type: "POST",
url: that.options.excel.createUrl,
contentType: "application/json; charset=utf-8",
dataType: "json",
data: JSON.stringify(data)
})
.done(function (e) {
// Download the spreadsheet.
window.location = kendo.format("{0}?title={1}",
that.options.excel.downloadUrl,
that.options.excel.title);
});
}
});
kendo.ui.plugin(ExcelGrid);
})(jQuery);
/*-----------------------------------------*/
function isValidEmailAddress(emailAddress) {
var pattern = new RegExp(/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i);
return pattern.test(emailAddress);
};
function checkboxDefaut() {
if ($("#defaut").is(":checked")) {
$("#lstColonnes input").each(function () {
$(this).attr("disabled", true);
})
}
else {
$("#lstColonnes input").each(function () {
$(this).removeAttr("disabled");
})
}
}
function onSelectSociete(e) {
$("#IdSociete").val(this.dataItem(e.item.index()).IdSociete);
}
function OuvrirDossierDansNouvelOnglet(pIdSocieteConsultee, pRecolte, pIdSitTypeProduction) {
var windowReference = window.open();
$.ajax({
data: "pIdSociete=" + pIdSocieteConsultee + "&pRecolte=" + pRecolte + "&pIdSitTypeProduction=" + pIdSitTypeProduction,
type: "POST",
url: "/Admin/GetUrlConsultationDossierDansNouvelOnglet",
async: true,
success:
function (res) {
if (res != null && res != "") {
windowReference.location = (encodeURI(res));
} else {
windowReference.close();
}
}
});
}
function ReInitDateModifContrat(pIdContratPhys)
{
$.ajax({
data: "pIdContratPhys=" + pIdContratPhys,
type: "POST",
url: "/Admin/ReInitDateModifContrat",
async: true,
success:
function (res) {
if (res== "") {
alert("La date de modification du contrat a été mise à jour");
}
},
error:function(res)
{
console.log(res);
}
});
}
function ModifMargePerso(pIdContratPhys, pGridName) {
$.ajax({
data: "pIdContratPhys=" + pIdContratPhys,
type: "POST",
url: "/Admin/LoadCwModifPersonnalisationMarge",
async: true,
success:
function (res) {
if (res != "")
{
$('#Window').contents().remove();
$('#Window').html(res);
}
},
error: function (res) {
console.log(res);
}
});
}
function AffecterLieuDestinationContrat(pIdContratPhys) {
$.ajax({
type: "POST",
data: { pIdContratPhys: pIdContratPhys },
url: '/AdminLogistique/LoadAffecterLieuDestinationContrat',
async: true,
success:
function (res) {
$('#Window').html(res);
},
error:
function (res) {
MsgBoxAlert("", "Une erreur est survenue", Icone.WarningOrange);
/*pIcone : Infos / WarningJaune / WarningOrange / Error / Alarme*/
}
});
}
function changeUser(pTypeProd, pRecolte, pIdUtilisateur) {
idSociete = $("#IdSociete").val();
if (typeof ($("#CbAnnee_consu").val()) != "undefined") {
pRecolte = $("#CbAnnee_consu").val();
}
if (typeof ($("#CbCulture_consu").val()) != "undefined") {
pTypeProd = $("#CbCulture_consu").val();
}
if (idSociete != -1) {
// AB le 28/05/15 : on ouvre toujours dans un nouvel onglet
// ça permet de visualiser la formule du user
// ex : j'ai formule type gephymat et je consulte un dossier price manager
OuvrirDossierDansNouvelOnglet(idSociete, pRecolte, pTypeProd, pIdUtilisateur);
}
else {
windowReference.close();
}
}
function onSearchSociete() {
return {
text: $("#searchSociete").val()
};
}
function onSearchSocieteByTc() {
return {
text: $("#searchSociete").val(),
TC: $("#comboTCPersonnalisationMarge").data("kendoDropDownList").value()
};
}
function selectTermeMarcheAlerteChange() {
var CodeMarche = $("#selectTermeMarche").data("kendoDropDownList").value();
$.ajax({
type: "POST",
url: '/Tools/SelectTermeMarcheAlerteChanged',
data: { pCodeMarche: CodeMarche },
async: true,
success:
function (res) {
$("#divSelectTermeContrat").contents().remove();
$("#divSelectTermeContrat").html(res);
}
});
}
function reactiverAlerte() {
var IdAlerte = document.getElementById("txtIdAlerte").value;
$.ajax({
type: "POST",
url: '/Tools/ReactiverAlerte',
data: { pIdAlerte: IdAlerte },
async: true,
success:
function (res) {
if (res == "") {
saveAlerte()
}
else {
MsgBoxAlert("", res, Icone.Infos);
}
}
});
}
/*---------------------Fonctions des pages du dossier Tools-----------------------*/
function saveAlerte() {
var IdAlerte = document.getElementById("txtIdAlerte").value;
//var ActionApresDeclenchement = document.getElementById("selectRenouvellement").value;
var TypeCours = document.getElementById("selectTypeCours").value;
var Sens = document.getElementById("selectSens").value;
var CodeMarche = document.getElementById("selectTermeMarche").value;
var CodeContrat = document.getElementById("selectTermeContrat").value;
if ($("#selectTermeContrat").data("kendoDropDownList").select() == 0) {
CodeContrat = "-1";
}
var Seuil = $("#txtCoursJour").data("kendoNumericTextBox").value();
var Commentaire = document.getElementById("txtCommentaire").value;
var EnvoiMail = document.getElementById("chkMail").checked;
var EnvoiSms = false;
try {
EnvoiSms = document.getElementById("chkSms").checked;
}
catch (e) { EnvoiSms = false; }
var MailCopie = "";
if (document.getElementById("chkMailCopie").checked == true) {
MailCopie = document.getElementById("txtMailCopie").value;
}
var MailDest = $("#txtMailDest").val();
var TelDest = $("#txtTelDest").val();
if ($("#chkSms").is(":checked") == true && (TelDest == null || TelDest == '')) {
MsgBoxAlert("", "Veuillez saisir un numéro de téléphone valide pour l'envoi de l'alerte par SMS.", Icone.Infos);
return;
}
if ($("#chkMailCopie").is(":checked") == true && (MailCopie == null || MailCopie == '')) {
MsgBoxAlert("", "Veuillez saisir un email pour recevoir une copie ou décocher la case 'Mail en copie à'.", Icone.Infos);
return;
}
else {
$.ajax({
type: "POST",
url: '/Tools/SaveAlerte',
data: { pIdAlerte: IdAlerte, pTypeCours: TypeCours, pSens: Sens, pCodeMarche: CodeMarche, pCodeContrat: CodeContrat, pSeuil: Seuil, pCommentaire: Commentaire, pEnvoiMail: EnvoiMail, pEnvoiSms: EnvoiSms, pEmailDest: MailDest, pTelDest: TelDest, pMailCopie: MailCopie },
async: true,
success:
function (res) {
if (res == "") {
menuClick('Tools', 'vMesAlertes');
onClose_ucChildWindow();
}
else {
MsgBoxAlert("", res, Icone.Infos);
}
}
});
}
}
function selectTermeContratAlerteChange() {
var idAlerte = document.getElementById("txtIdAlerte").value;
if (idAlerte <= 0) {
var CodeContrat = $("#selectTermeContrat").data("kendoDropDownList").value();
if (CodeContrat == '' || CodeContrat == null) {
CodeContrat = document.getElementById("txtPremierTC").value;
}
$.ajax({
type: "POST",
url: '/Tools/GetCotationVolatiliteContrat',
data: { pCodeContrat: CodeContrat },
async: true,
success:
function (res) {
//if ($("#selectSens").val() == 'D')
// $("#txtCoursJour").data("kendoNumericTextBox").value(parseFloat(res.split('|')[0]) - 1.00);
//else
// $("#txtCoursJour").data("kendoNumericTextBox").value(parseFloat(res.split('|')[0]) + 1.00);
$("#txtCoursJour").data("kendoNumericTextBox").value(res.split('|')[0]);
}
});
}
}
function AjouterAlerte() {
AfficheSaisieAlerte(-1);
}
function AfficheSaisieAlerte(pIdAlerte) {
$.ajax({
type: "POST",
url: '/Tools/LoadCwSaisieAlerte',
data: { pIdAlerte: pIdAlerte },
async: true,
success:
function (res) {
$('#Window').contents().remove();
$('#Window').html(res);
}
});
}
function ModifierAlerte() {
var monGrid = $("#GridMesAlertes").data("kendoGrid");
var selectedItem = monGrid.dataItem(monGrid.select());
if (selectedItem != null) {
var idAlerte = selectedItem.IdAlerte;
AfficheSaisieAlerte(idAlerte);
}
else {
MsgBoxAlert("", $("#SelectionnerAlertModifier").val().replace(/\\n/g, "\n"), Icone.Infos);
}
}
function GridMesAlertesDoubleClick() {
var monGrid = $("#GridMesAlertes").data("kendoGrid");
var selectedItem = monGrid.dataItem(monGrid.select());
if (selectedItem != null) {
ModifierAlerte();
}
}
function SupprimerAlerte() {
var monGrid = $("#GridMesAlertes").data("kendoGrid");
var selectedItem = monGrid.dataItem(monGrid.select());
if (selectedItem != null) {
if (confirm($("#ConfirmerSuppression").val())) {
var idAlerte = selectedItem.IdAlerte;
$.ajax({
type: "POST",
url: '/Tools/DeleteAlerte',
data: { pIdAlerte: idAlerte },
async: true,
success:
function (res) {
menuClick('Tools', 'vMesAlertes');
}
});
}
}
else {
MsgBoxAlert("", $("#SelectionnerAlertSupprimer").val().replace(/\\n/g, "\n"), Icone.Infos);
}
}
function tpl_sensAlerte_Fleche(pValue) {
var retour = "";
if (pValue == "D") {
retour = "";
}
else {
retour = "";
}
return retour;
}
function selectTermeContratPricerChange() {
var CodeContrat = $("#selectTermeContrat").data("kendoDropDownList").value();
var CodeMarche = $("#selectTermeMarche").data("kendoDropDownList").value();
if (CodeContrat != "") {
$.ajax({
type: "POST",
url: '/Tools/GetCotationVolatiliteContrat',
data: { pCodeMarche: CodeMarche, pCodeContrat: CodeContrat },
async: true,
success:
function (res) {
$("#txtCoursJour").data("kendoNumericTextBox").value(res.split('|')[0]);
$("#txtPrixExercice").data("kendoNumericTextBox").value(res.split('|')[1]);
$("#txtVolatilite").data("kendoNumericTextBox").value(res.split('|')[2]);
$.ajax({
type: "POST",
url: '/Tools/GetChaineEcheanceOption',
data: { pCodeContrat: CodeContrat },
async: true,
success:
function (res) {
$("#divEcheanceOption").html(res);
$("#txtDateClotureOption").val(res);
MajMaturite();
}
});
}
});
}
}
function selectTermeMarchePricerChange() {
var CodeMarche = $("#selectTermeMarche").data("kendoDropDownList").value();
$.ajax({
type: "POST",
url: '/Tools/SelectTermeMarchePricerChanged',
data: { pCodeMarche: CodeMarche },
async: true,
success:
function (res) {
$("#divSelectTermeContrat").html(res);
}
});
}
function MajMaturite() {
var DateAchat = $("#dpDateAchat").val();
var DateClotureOption = $("#txtDateClotureOption").val();
var date1 = new Date(DateAchat.split('/')[2], DateAchat.split('/')[1] - 1, DateAchat.split('/')[0]);
var date2 = new Date(DateClotureOption.split('/')[2], DateClotureOption.split('/')[1] - 1, DateClotureOption.split('/')[0]);
if (date1 > date2) {
MsgBoxAlert("", $("#DateAchatSuperieurDateCloture").val().replace(/\\n/g, "\n"), Icone.Infos);
date1 = date2;
$("#dpDateAchat").data("kendoDatePicker").value(date1);
}
var diffMilliseconde = date2 - date1;
var diffJour = diffMilliseconde / (1000 * 3600 * 24);
var chaineMaturite = Math.round(diffJour);
$("#divMaturite").html(chaineMaturite);
//TODO Demander à Emmanuel si la valeur de volatilité à utiliser est la moyenne calculée depuis les data de la base ou celle renseignée par le formulaire
CalculPrimePricer();
}
function CalculPrimePricer(volatiliteSasie) {
CoursJour = $("#txtCoursJour").data("kendoNumericTextBox").value();
CoursExercice = $("#txtPrixExercice").data("kendoNumericTextBox").value();
if (volatiliteSasie == "true") {
Volatilite = $("#txtVolatilite").data("kendoNumericTextBox").value();
}
else {
Volatilite = null;
}
DateClotureOption = $("#txtDateClotureOption").val();
DateAchat = $("#dpDateAchat").val();
TypeOption = $("#selectTypeOperation").val();
CodeMarche = $("#selectTermeMarche").data("kendoDropDownList").value();
CodeContrat = $("#selectTermeContrat").data("kendoDropDownList").value();
$.ajax({
type: "POST",
url: '/Tools/GetPrimePricer',
data: {
"pCoursJours": CoursJour, "pCoursExercice": CoursExercice, "pVolatilite": Volatilite, "pDateClotureOption": DateClotureOption,
"pDateAchat": DateAchat, "pTypeOption": TypeOption, "pCodeMarche": CodeMarche, "pCodeContrat": CodeContrat
},
async: true,
success:
function (res) {
$("#divPrime").html($("#TxtPrime").val() + " " + TypeOption + " : " + res.Prime + " €/T");
$("#txtPrimeOption").val(res.Prime);
if (Volatilite == null) {
$("#txtVolatilite").data("kendoNumericTextBox").value(res.Volatilite);
}
}
});
}
function CalculPrimePricerFromVolatilite() {
CalculPrimePricer("true");
}
function AjouterCalculGrid() {
//AjouterCalculGrid(string pDateAchat, string pLibelleMarche, string pLibelleContrat, string pTypeOption, decimal pPrixExercice, decimal pPrime, decimal pVolatilite, decimal pCoursJour)
var DateAchat = document.getElementById("dpDateAchat").value;
var TermeMarche = $("#selectTermeMarche").data("kendoDropDownList").text();
var TermeContrat = $("#selectTermeContrat").data("kendoDropDownList").text();
var TypeOption = $("#selectTypeOperation").data("kendoDropDownList").value();
var PrixExercice = $("#txtPrixExercice").data("kendoNumericTextBox").value();
var Prime = document.getElementById("txtPrimeOption").value;
var Volatilite = $("#txtVolatilite").data("kendoNumericTextBox").value();
var CoursJour = $("#txtCoursJour").data("kendoNumericTextBox").value();
$.ajax({
type: "POST",
url: '/Tools/AjouterCalculGrid',
data: { pDateAchat: DateAchat, pLibelleMarche: TermeMarche, pLibelleContrat: TermeContrat, pTypeOption: TypeOption, pPrixExercice: PrixExercice, pPrime: Prime, pVolatilite: Volatilite, pCoursJour: CoursJour },
async: true,
success:
function (res) {
$("#divGridCalcul").contents().remove();
$("#divGridCalcul").html(res);
}
});
}
function SupprimerCalculGrid() {
var monGrid = $("#GridCalculPricer").data("kendoGrid");
var selectedItem = monGrid.dataItem(monGrid.select());
if (selectedItem != null) {
var idCalculPricer = selectedItem.IdCalculPricer;
$.ajax({
type: "POST",
url: '/Tools/SupprimerCalculGrid',
data: { pIdCalculPricer: idCalculPricer },
async: true,
success:
function (res) {
$("#divGridCalcul").contents().remove();
$("#divGridCalcul").html(res);
}
});
}
}
function selectTermeMarcheExportChange() {
var CodeMarche = $("#selectTermeMarcheExport").data("kendoDropDownList").value();
var monGrid = $("#GridCotations").data("kendoGrid");
var selectedItem = monGrid.dataItem(monGrid.select());
var CodeContrat = selectedItem.CodeContrat;
$.ajax({
type: "POST",
url: '/Gephycotes/selectTermeMarcheExportChanged',
data: { pCodeMarche: CodeMarche, pCodeContrat: CodeContrat },
async: true,
success:
function (res) {
$("#divGridEcheance").contents().remove();
$("#divGridEcheance").html(res);
}
});
}
function onClose_cwSupport() {
$("#cwSupport").data("kendoWindow").destroy();
}
function GetTableauDeBordByGroupe(pGroupePage) {
loading();
$.ajax({
type: "POST",
url: "/AdminTableauDeBord/getTableauDeBord",
data: {pGroupePage : pGroupePage},
async: true,
success:
function (res) {
$("#divTableauDeBord").html(res);
$("#divTableauDeBord").show();
stopLoading();
}
});
}
function ValiderObjectifAtteint(pIdContratPhys, pIdElementPrixVP)
{
var data = {};
data.pIdContratPhys = pIdContratPhys;
data.pIdElementPrixVP = pIdElementPrixVP;
$.ajax({
type: "POST",
url: '/Gephytrade/LoadUcValidationObjectifAtteint',
data: data,
async: true,
success:
function (res) {
$('#Window').contents().remove();
$('#Window').html(res);
}
});
}
// Background-color quand input est focus,
// et select le text(couleur du texte selectionné a personaliser
// car invisible dans les grid kendo)
function input_focus(element) {
element.focus(function (e) {
$(this).css({ "background-color": "#ffa" });
var input = $(this);
setTimeout(function () {
input.select();
});
});
element.blur(function (e) {
$(this).css({ "background-color": "#fff" });
});
}
//fonction pour lancer une fonction (ex: formulaire) quand la touch ENTRER est utilisée
function SendFormulaireTouchEnter(event, functionForm) {
if (event.keyCode == 13) {
functionForm();
}
}
/*-----------------------------------------------------*/