$(window).on('load', function (){
let evaPostUrl="/wp-content/themes/hosteva/eva/post/get.php";
let evaPostLimitCheckUrl="/wp-content/themes/hosteva/eva/post/fiyat-teklifi-iste-limit.php";
let d=$("#offerCreate"), cClass="collapse";
let country=d.find("select#selectUlke"), city=d.find("select#selectSehir"), school=d.find("select#selectOkul"), eduProduct=d.find("select.eduProduct"), stayProduct=d.find("select.stayProduct"), otherProduct=d.find("select.otherProduct");
let eduDate=d.find("input.eduDate"), eduWeek=d.find("select.eduWeek"), stayDate=d.find("input.stayDate"), stayWeek=d.find("select.stayWeek");
let eduClass=".edu", edu=d.find(eduClass), stayClass=".stay", stay=d.find(stayClass), otherClass=".other", other=d.find(otherClass), otherProductList=other.find(".product-list"), eduProductList=edu.find(".product-list"), stayProductList=stay.find(".product-list");
let offerViewClass=".offerView", offerView=d.find(offerViewClass), offerSchool=offerView.find(".offerSchool"), offerEdu=offerView.find(".offerEdu"), offerStay=offerView.find(".offerStay"), offerOther=offerView.find(".offerOther"), offerImg=d.find(".offerImg");
let offerLastStep=d.find("#offerLastStep"), phoneNumberCheck=offerLastStep.find(".phoneNumberCheck"), uName=offerLastStep.find("input.userNameSurname"), uCity=offerLastStep.find("select.userCity"),   uPhone=offerLastStep.find("input.userPhone"), uEmail=offerLastStep.find("input.userEmail");
country.val("");
offerLastStep.find("input[type='text'],input[type='email'],input[type='number']").val("");
offerLastStep.find("select").val("");
let eduDisabledDays=[0, 2, 3, 4, 5, 6];
let eduDateDP=eduDate.datepicker({
language: 'en',
firstDay: 1,
minDate: new Date(),
autoClose: !0,
dateFormat: "yyyy-mm-dd",
position: "bottom left",
onRenderCell: function (date, cellType){
if(cellType=='day'){
var day=date.getDay(), isDisabled=eduDisabledDays.indexOf(day)!=-1;
return {
disabled: isDisabled
}}
},
onSelect: function onSelect(fd, date){
let t=eduDate, v=t.val();
eduDateAfterClear();
if(v){
eduProduct.prop('disabled', false);
}}
});
eduDate.on('focus', function (e){
eduDateDP.show();
e.preventDefault();
});
function offerClear(){
offerView.find("tbody").html("");
offerCheck();
}
function offerStayClear(){
offerStay.find("tbody").html("");
offerCheck();
}
function offerEduClear(){
offerEdu.find("tbody").html("");
offerCheck();
}
function offerOtherClear(){
offerOther.find("tbody > tr").each(function (){
if(!$(this).hasClass("required")){
$(this).remove();
}});
offerCheck();
}
function offerCheck(){
offerView.addClass(cClass);
offerSchool.addClass(cClass);
offerEdu.addClass(cClass);
offerStay.addClass(cClass);
offerOther.addClass(cClass);
if(offerSchool.find("tbody tr").length){
offerSchool.removeClass(cClass);
}
if(offerEdu.find("tbody tr").length){
offerEdu.removeClass(cClass);
}
if(offerStay.find("tbody tr").length){
offerStay.removeClass(cClass);
}
if(offerOther.find("tbody tr").length){
offerOther.removeClass(cClass);
}
if(offerView.find(".collapse").length < 4){
offerView.removeClass(cClass);
offerImg.addClass(cClass);
}else{
offerImg.removeClass(cClass);
}}
function countryAfterClear(){
city.val("").prop('disabled', 'disabled');
cityAfterClear();
}
function cityAfterClear(){
school.val("").prop('disabled', 'disabled');
schoolAfterClear();
}
function schoolAfterClear(){
eduProduct.val("").prop('disabled', 'disabled');
offerEdu.find("tbody").html("");
offerStay.find("tbody").html("");
eduAfterClear();
}
function eduAfterClear(){
eduDate.val("").prop('disabled', 'disabled');
eduDateAfterClear();
}
function eduDateAfterClear(){
eduWeek.val("").prop('disabled', 'disabled');
eduWeekAfterClear();
}
function eduWeekAfterClear(){
eduProduct.val("").prop('disabled', 'disabled');
eduProductAfterClear();
}
function eduProductAfterClear(){
eduProductList.html("");
stay.addClass(cClass);
stayDate.val("").prop('disabled', 'disabled');
stayDateAfterClear();
}
function stayDateAfterClear(){
stayWeek.val("").prop('disabled', 'disabled');
stayWeekAfterClear();
}
function stayWeekAfterClear(){
stayProduct.val("").prop('disabled', 'disabled');
stayProductAfterClear();
}
function stayProductAfterClear(){
stayProductList.html("");
offerStayClear();
}
let offerSwiper=new Swiper(d.find(".swiper-container"), {
loop: !1,
passiveListeners: false,
allowTouchMove: !1,
spaceBetween: 0,
speed: 400,
pagination: {
el: '.swiper-pagination',
renderBullet: function (index, className){
return '<span class="' + className + '" data-index="' + index + '">' + d.find(".swiper-container .swiper-slide").eq(index).data("title") + '</span>';
}}
});
d.find(".swiper-container .swiper-pagination > span").addClass("disabled").removeClass("completed");
function offerSwiperGo(index){
let con=d.find(".swiper-container"), conSw=con.find(".swiper-slide"), sp=con.find(".swiper-pagination > span"), spC="completed", spD="disabled", spl=sp.length;
if(index > 0){
for (let zz=0; zz < index; zz++){
sp.eq(zz).addClass(spC).removeClass(spD);
conSw.eq(zz).addClass(spC);
}}else{
sp.addClass(spD).removeClass(spC);
sp.eq(index).removeClass(spD);
}
if((index + 1) < spl){
for (let zz=index + 1; zz <=spl; zz++){
sp.eq(zz - 1).removeClass(spC).addClass(spD);
}}
if(uPhone.hasClass("verify")){
offerLastStep.find("button").addClass("btn-offer-complete").removeClass("disabled").attr("disabled", false);
}
offerSwiper.slideTo(index);
}
$(document).on("change", "#offerCreate #selectUserCity", function (){
var sc=$("#offerCreate #subeContainer"),sw=$("#offerCreate #subeWrapper"),c="collapse";
var x=$(this).find("option:selected").val();
console.log(uCity);
if(x==34){
if(sc.find("select.sube-34").length<=0){
sc.html('<div class="form-group"><select class="form-control sube-34" id="SubeKodu" name="SubeKodu"  data-required-text="Hizmet almak istediğiniz şubeyi seçmeniz gerekir!" required><option disabled value="" >- Şube Seçiniz -</option><option value="BSH">Bahçeşehir</option><option value="BKR">Bakırköy</option><option value="IST">Beşiktaş</option><option value="KDKY">Kadıköy</option></select></div>');
sc.find("select").val("");
}
sw.removeClass(c);
}else{
sw.addClass(c);
sc.html("");
}});
$(document).on("click", "#offerCreate .swiper-container .swiper-pagination > span", function (){
if(!$(this).hasClass("disabled")){
offerSwiperGo($(this).data("index"));
}else{
return false;
}});
$(document).on("click", "#offerCreate .swiper-container .btn-next", function (){
offerSwiperGo($(this).parents(".swiper-container").find(".swiper-pagination .swiper-pagination-bullet-active").data("index") + 1);
});
$(document).on("change","#offerCreate select#selectUlke", function (){
let t=$(this), v=t.find(":selected").val();
if(v){
countryAfterClear();
$.post(evaPostUrl, { process: "getCityList", ulkeKodu: v }, function (data){
if(data){
city.find("option:not(:eq(0))").remove();
var x={};
$.each(data, function (key, data){
if(!(data.Adi in x)){
x[data.Adi]=data.Kodu;
city.append("<option value='" + data.Kodu + "'>" + data.Adi + "</option>");
}});
city.prop('disabled', false);
}else{
eltAlert("Şehirler alınamadı!", "danger");
countryAfterClear();
}}, "json");
$.post(evaPostUrl, { process: "getSchoolList", ulkeKodu: v }, function (data){
if(data){
school.find("option:not(:eq(0))").remove();
$.each(data, function (key, data){
school.append("<option value='" + data.MekezKodu + "' data-description='" + data.Aciklama + "' data-rate='" + data.ParaBirimi + "' data-city='" + data.Sehir.replace(/'/g, "") + "'>" + data.Aciklama + "</option>");
});
}else{
eltAlert("Okullar alınamadı!", "danger");
countryAfterClear();
}}, "json");
t.parents(".swiper-slide").removeClass("completed");
}});
$(document).on("change","#offerCreate select#selectSehir", function (){
let t=$(this), s=t.find(":selected"), v=s.val();
if(v){
let o=school.find("option[data-city='" + jQuery.trim(s.text()).replace(/'/g, "") + "']");
cityAfterClear();
if(school.find("option").length > 1&&o.length){
school.find("option").addClass(cClass);
school.find("option").eq(0).removeClass(cClass);
o.removeClass(cClass);
school.prop('disabled', false);
t.parents(".swiper-slide").removeClass("completed");
}else{
eltAlert("Okullar alınamadı!", "danger");
cityAfterClear();
}}
});
$(document).on("change","#offerCreate select#selectOkul", function (){
let t=$(this), s=t.find(":selected"), v=s.val();
if(v){
offerSchool.find("tbody").html("");
schoolAfterClear();
$.post(evaPostUrl, { process: "getProductList", merkezKodu: v }, function (data){
if(data){
eduProduct.find("option:not(:eq(0))").remove();
stayProduct.find("option:not(:eq(0))").remove();
otherProduct.find("option:not(:eq(0))").remove();
otherProductList.html("");
eduWeek.find("option:not(:eq(0))").remove();
stayWeek.find("option:not(:eq(0))").remove();
let eduSelectWeeks=[], staySelectWeeks=[];
$.each(data, function (key, data){
if(jQuery.inArray(data.UrunTipiAciklama, ["EĞİTİM", "AKADEMİK UZUN DÖNEM", "EĞİTİM + OTEL KONAKLAMA", "EĞİTİM + AILE YANI KONAKLAMA", "EĞİTİM + YURT KONAKLAMA", "EĞİTİM + KONAKLAMA + UÇAK BİLETİ"])!==-1){
eduProduct.append("<option value='" + data.UrunKodu + "' data-free-stay='" + data.KonaklamaDahil + "' data-min-week='" + data.MinHafta + "' data-max-week='" + data.MaxHafta + "' data-required='" + data.Zorunlu + "' data-type='" + data.UrunTipiAciklama + "' data-name='" + data.UrunAciklama + "'>" + data.UrunAciklama + "</option>");
if(data.MinHafta > 0){
if(data.MinHafta==data.MaxHafta){
if($.inArray(data.MinHafta, eduSelectWeeks) < 0){
eduSelectWeeks.push(data.MinHafta);
}}else{
for (let zz=data.MinHafta; zz <=data.MaxHafta; zz++){
if($.inArray(zz, eduSelectWeeks) < 0){
eduSelectWeeks.push(zz);
}}
}}
}
else if(jQuery.inArray(data.UrunTipiAciklama, ["KONAKLAMA"])!==-1){
stayProduct.append("<option value='" + data.UrunKodu + "' data-min-week='" + data.MinHafta + "' data-max-week='" + data.MaxHafta + "' data-required='" + data.Zorunlu + "' data-type='" + data.UrunTipiAciklama + "' data-name='" + data.UrunAciklama + "'>" + data.UrunAciklama + "</option>");
if(data.MinHafta > 0){
if(data.MinHafta==data.MaxHafta){
if($.inArray(data.MinHafta, staySelectWeeks) < 0){
staySelectWeeks.push(data.MinHafta);
}}else{
for (let zz=data.MinHafta; zz <=data.MaxHafta; zz++){
if($.inArray(zz, staySelectWeeks) < 0){
staySelectWeeks.push(zz);
}}
}}
}else{
otherProduct.append("<option value='" + data.UrunKodu + "' data-min-week='" + data.MinHafta + "' data-max-week='" + data.MaxHafta + "' data-required='" + data.Zorunlu + "' data-type='" + data.UrunTipiAciklama + "' data-name='" + data.UrunAciklama + "'>" + data.UrunAciklama + "</option>");
}});
eduSelectWeeks.sort(function (a, b){
return parseInt(a) - parseInt(b);
});
staySelectWeeks.sort(function (a, b){
return parseInt(a) - parseInt(b);
});
$.each(eduSelectWeeks, function (ind, val){
eduWeek.append("<option value='" + val + "'>" + val + " Hafta</option>");
});
$.each(staySelectWeeks, function (ind, val){
stayWeek.append("<option value='" + val + "'>" + val + " Hafta</option>");
});
eduDate.prop('disabled', false);
edu.removeClass(cClass);
otherProduct.find("option[data-required='true']").addClass(cClass);
offerSchool.find("tbody").append("<tr><td><div class='product-name'>" + s.text() + "</div><div>" + city.find(":selected").text() + " - " + country.find(":selected").text() + "</div></td><td><button class='btn btn-danger btn-sm btn-delete'><i class='fa fa-times'></i></button></td></tr>");
offerCheck();
offerSwiperGo(1);
}else{
eltAlert("Okullar alınamadı!", "danger");
schoolAfterClear();
}}, "json");
}});
eduDate.change(function (){
let t=$(this), v=t.val();
eduDateAfterClear();
if(v){
eduProduct.prop('disabled', false);
t.parents(".swiper-slide").removeClass("completed");
}});
eduProduct.change(function (){
eduWeek.val("");
let t=$(this), s=t.find(":selected"), v=s.val(), text=s.text();
if(v){
eduProductAfterClear();
var showWeeks=[];
$.post(evaPostUrl, { process: "getProductPriceList", urunKodu: v }, function (data){
if(data){
$.each(jQuery.parseJSON(data), function (index, value){
if(value.Onay&&dateBetweenCheck(value.BaslangicTarihi, value.BitisTarihi)){
if(value.MinHafta==value.MaxHafta&&jQuery.inArray(value.MaxHafta, showWeeks) < 0){
showWeeks.push(value.MaxHafta);
}}
});
let opC=0, opV="";
if(showWeeks.length > 0){
eduWeek.find("option").not(':first').remove();
eduWeek.find("option").eq(0).removeClass(cClass);
$.each(showWeeks, function (ind, val){
eduWeek.append("<option value='" + val + "'>" + val + " Hafta</option>");
opC++;
opV=val;
});
}else{
eduWeek.find("option").addClass(cClass);
eduWeek.find("option").eq(0).removeClass(cClass);
eduWeek.find("option").each(function (){
if(jQuery.isNumeric($(this).val())&&$(this).val() >=s.data("min-week")&&$(this).val() <=s.data("max-week")){
$(this).removeClass(cClass);
opC++;
opV=$(this).val();
}});
}
eduWeek.prop('disabled', false);
if(opC==1){
eduWeek.val(opV).change();
t.parents(".swiper-slide").removeClass("completed");
}else{
eduWeek.val("").change();
}
offerCheck();
}else{
eltAlert("veri alınamadı.", "danger");
}});
}else{
eduProductAfterClear();
}});
eduWeek.change(function (){
let t=$(this), v=t.find(":selected").val();
offerEduClear();
if(v&&jQuery.isNumeric(v)){
$.post(evaPostUrl, { process: "getProductPriceList", urunKodu: eduProduct.find(":selected").val() }, function (data){
if(data){
let eduWeekVal=eduWeek.val(), maxWeek=0, minWeek=9999999, prodsAll=[], prodsWithOldPrice=[], prodsEnd=[];
$.each(jQuery.parseJSON(data), function (index, value){
if(value.Onay&&dateBetweenCheck(value.BaslangicTarihi, value.BitisTarihi)){
if(eduWeekVal >=value.MinHafta&&eduWeekVal <=value.MaxHafta){
if(value.FiyatTipi=="Katalog Fiyatı"){
prodsWithOldPrice.push(value);
}
prodsAll.push(value);
}
if(value.MaxHafta > maxWeek){
maxWeek=value.MaxHafta;
}
if(value.MinHafta < minWeek){
minWeek=value.MinHafta;
}}
});
if(prodsAll.length <=0){
eduProductList.html("hafta minimum " + minWeek + ", maksimum " + maxWeek + " olmalıdır.");
eltAlert("hafta minimum " + minWeek + ", maksimum " + maxWeek + " olmalıdır.");
}
$.each(prodsAll, function (index, value){
if(value.FiyatTipi!="Katalog Fiyatı"){
let x=[];
x["Discount"]=0;
x["OldPrice"]=0;
x["EndPrice"]=value.Fiyat;
x["MinWeek"]=value.MinHafta;
x["MaxWeek"]=value.MaxHafta;
x["Season"]=value.Sezon;
x["Rate"]=school.find(":selected").data("rate");
$.each(prodsWithOldPrice, function (ii, vv){
if(value.MinHafta==vv.MinHafta&&value.MaxHafta==vv.MaxHafta&&value.Sezon==vv.Sezon){
x["OldPrice"]=vv.Fiyat;
x["Discount"]=vv.Fiyat - value.Fiyat;
}});
prodsEnd.push(x);
}});
$.each(prodsAll, function (index, value){
if(value.FiyatTipi=="Katalog Fiyatı"){
let x=[];
x["Discount"]=0;
x["OldPrice"]=0;
x["EndPrice"]=value.Fiyat;
x["MinWeek"]=value.MinHafta;
x["MaxWeek"]=value.MaxHafta;
x["Season"]=value.Sezon;
x["Rate"]=school.find(":selected").data("rate");
if(prodsEnd.length <=0){
prodsEnd.push(x);
}else{
$.each(prodsEnd, function (ii, vv){
if(value.MinWeek!=vv.MinHafta&&value.MaxWeek!=vv.MaxHafta){
prodsEnd.push(x);
}});
}}
});
if(prodsEnd.length){
let html="";
$.each(prodsEnd, function (index, value){
var s=eduProduct.find(":selected"), text=s.text();
html +="<div class='product-item'>";
html +="<div class='row'>";
html +="<div class='col-sm'>";
html +="<div class='product-description'>";
html +="<div class='product-name'>" + text + "</div>";
html +="<div class='season'>" + value.Season + " Sezonu</div>";
html +="<div class='week'><span>" + eduWeekVal + "</span> Hafta</div>";
html +="<div class='start'><span>" + eduDate.val() + "</span> Başlangıç</div>";
html +="</div>";
html +="</div>";
html +="<div class='col-sm-auto'>";
html +="<button data-id='" + v + "' data-type='" + s.data("type") + "' data-name='" + text + "' class='btn btn-primary btn-sm'>EKLE</button>";
html +="</div>";
html +="</div>";
html +="</div>";
});
eduProductList.html(html);
eduProductList.find("button").removeClass("disabled").attr("disabled", false);
eduProductList.find("button").each(function (){
if(offerEdu.find("tr[data-id='" + $(this).data("id") + "']").length){
$(this).addClass("disabled").attr("disabled", "disabled").html("EKLENDİ");
}else{
$(this).click();
if(eduProduct.find(":selected").data("free-stay")==1){
stayProduct.prop('disabled', false);
stayWeek.prop('disabled', false);
var date=new Date(eduDate.val()), newdate=new Date(date);
newdate.setDate(newdate.getDate() - 1);
let nM=(newdate.getMonth() + 1), nD=(newdate.getDate());
if(nM < 10){
nM="0" + nM;
}
if(nD < 10){
nD="0" + nD;
}
stayDate.val(newdate.getFullYear() + "-" + nM + "-" + nD).change();
stayWeek.append("<option value='" + eduWeek.val() + "'>" + eduWeek.val() + "</option>");
stayWeek.val(eduWeek.val());
offerCheck();
other.removeClass(cClass);
offerSwiperGo(3);
}else{
offerSwiperGo(2);
}}
});
}}else{
eltAlert("Kurslar alınamadı!", "danger");
}}, "html");
}});
$(document).on("click", eduClass + " .product-list button", function (){
let btn=$(this), pi=btn.parents(".product-item"), trId=eduProduct.find(":selected").val();
if(offerEdu.find("tr[data-id='" + trId + "']").length <=0){
btn.html("EKLENDİ");
offerEdu.find("tbody").html("");
offerEdu.find("tbody").append("<tr data-id='" + trId + "' data-type='" + btn.data("type") + "' data-name='" + btn.data("name") + "' ><td>" + pi.find(".product-description").html() + "</td><td><button class='btn btn-danger btn-sm btn-delete'><i class='fa fa-times'></i></button></td></tr>");
eduProductList.find("button").addClass("disabled").attr("disabled", "disabled");
stay.removeClass(cClass);
var date=new Date(eduDate.val());
var newdate=new Date(date);
newdate.setDate(newdate.getDate() - 1);
let nM=(newdate.getMonth() + 1);
if(nM < 10) nM="0" + nM;
let nD=(newdate.getDate());
if(nD < 10) nD="0" + nD;
newDate=newdate.getFullYear() + "-" + nM + "-" + nD;
stayDate.attr("min", newDate).attr("max", newDate).val(newDate);
stayProduct.prop('disabled', false);
offerOther.find("tbody").html("");
otherProductList.html("");
otherProduct.find("option").each(function (){
let t=$(this), v=t.val(), text=t.text();
if(v){
$.post(evaPostUrl, { process: "getProductPriceList", urunKodu: v }, function (data){
if(data){
if(t.data("required")=="true"||t.data("required")==true){
$.each(data, function (key, value){
if(value.Onay&&dateBetweenCheck(value.BaslangicTarihi, value.BitisTarihi)){
let eduWeekVal=eduWeek.val(), maxWeek=0, minWeek=9999999,
rate=school.find(":selected").data("rate");
if((value.MinHafta&&value.MaxHafta&&eduWeekVal >=value.MinHafta&&eduWeekVal <=value.MaxHafta)||(value.MinHafta < 0)){
offerOther.find("tbody").append("<tr data-id='" + v + "' class='required'><td><div class='product-name'>" + text + "</div></td><td class='price'><span>" + value.Fiyat + "</span>" + rate + "</td><td></td></tr>");
}
offerCheck();
}});
}else{
$.each(data, function (key, value){
let html="";
if(otherProductList.find("button[data-id='" + v + "']").length <=0){
html +="<div class='product-item'>";
html +="<div class='row'>";
html +="<div class='col-sm'>";
html +="<div class='product-description'>";
html +="<div class='product'>" + text + "</div>";
html +="</div>";
html +="</div>";
html +="<div class='col-sm-auto'>";
html +="<button data-id='" + v + "' data-type='" + t.data("type") + "' data-name='" + text + "' class='btn btn-primary btn-sm'>EKLE</button>";
html +="</div>";
html +="</div>";
html +="</div>";
}
if(html){
otherProductList.append(html);
}});
}}
offerCheck();
}, "json");
}});
offerCheck();
}else{
eltAlert("Eklenemedi", "danger");
}});
stayWeek.change(function (){
let t=$(this), v=t.val();
offerStayClear();
if(v&&jQuery.isNumeric(v)){
$.post(evaPostUrl, { process: "getProductPriceList", urunKodu: stayProduct.val() }, function (data){
if(data){
let stayWeekVal=v, maxWeek=0, minWeek=9999999, prodsAll=[], prodsWithOldPrice=[], prodsEnd=[];
$.each(jQuery.parseJSON(data), function (index, value){
if(value.Onay&&dateBetweenCheck(value.BaslangicTarihi, value.BitisTarihi)){
if(stayWeekVal >=value.MinHafta&&stayWeekVal <=value.MaxHafta){
if(value.FiyatTipi=="Katalog Fiyatı"){
prodsWithOldPrice.push(value);
}
prodsAll.push(value);
}
if(value.MaxHafta > maxWeek){
maxWeek=value.MaxHafta;
}
if(value.MinHafta < minWeek){
minWeek=value.MinHafta;
}}
});
if(prodsAll.length <=0){
if(maxWeek){
stayProductList.html("hafta minimum " + minWeek + ", maksimum " + maxWeek + " olmalıdır.");
}else{
stayProductList.html("veri alınamadı.");
}}
$.each(prodsAll, function (index, value){
if(value.FiyatTipi!="Katalog Fiyatı"){
let x=[];
x["Discount"]=0;
x["OldPrice"]=0;
x["EndPrice"]=value.Fiyat;
x["MinWeek"]=value.MinHafta;
x["MaxWeek"]=value.MaxHafta;
x["Season"]=value.Sezon;
x["Rate"]=school.find(":selected").data("rate");
$.each(prodsWithOldPrice, function (ii, vv){
if(value.MinHafta==vv.MinHafta&&value.MaxHafta==vv.MaxHafta&&value.Sezon==vv.Sezon){
x["OldPrice"]=vv.Fiyat;
x["Discount"]=vv.Fiyat - value.Fiyat;
}});
prodsEnd.push(x);
}});
$.each(prodsAll, function (index, value){
if(value.FiyatTipi=="Katalog Fiyatı"){
let x=[];
x["Discount"]=0;
x["OldPrice"]=0;
x["EndPrice"]=value.Fiyat;
x["MinWeek"]=value.MinHafta;
x["MaxWeek"]=value.MaxHafta;
x["Season"]=value.Sezon;
x["Rate"]=school.find(":selected").data("rate");
if(prodsEnd.length <=0){
prodsEnd.push(x);
}else{
$.each(prodsEnd, function (ii, vv){
if(value.MinHafta!=vv.MinHafta&&value.MaxHafta!=vv.MaxHafta){
prodsEnd.push(x);
}});
}}
});
if(prodsEnd.length){
let html="";
$.each(prodsEnd, function (index, value){
var s=stayProduct.find(":selected"), text=s.text();
html +="<div class='product-item'>";
html +="<div class='row'>";
html +="<div class='col-sm'>";
html +="<div class='product-description'>";
html +="<div class='product-name'>" + text + "</div>";
html +="<div class='season'>" + value.Season + " Sezonu</div>";
html +="<div class='week'><span>" + stayWeekVal + "</span> Hafta</div>";
html +="<div class='start'><span>" + stayDate.val() + "</span> Başlangıç</div>";
html +="</div>";
html +="</div>";
html +="<div class='col-sm-auto'>";
html +="<button data-id='" + v + "' data-type='" + s.data("type") + "' data-name='" + text + "' class='btn btn-primary btn-sm'>EKLE</button>";
html +="</div>";
html +="</div>";
html +="</div>";
});
stayProductList.html(html);
stayProductList.find("button").removeClass("disabled").attr("disabled", false);
stayProductList.find("button").each(function (){
if(offerStay.find("tr[data-id='" + $(this).data("id") + "']").length){
$(this).addClass("disabled").attr("disabled", "disabled").html("EKLENDİ");
}else{
$(this).click();
}});
t.parents(".swiper-slide").removeClass("completed");
}else{
if(maxWeek){
eltAlert("hafta minimum " + minWeek + ", maksimum " + maxWeek + " olmalıdır.", "danger");
}else{
eltAlert("veri alınamadı.", "danger");
}}
}else{
eltAlert("Konaklamalar alınamadı!", "danger");
}}, "html");
}});
stayProduct.change(function (){
stayWeek.val("");
let t=$(this), s=t.find(":selected"), v=s.val(), text=s.text();
if(v){
stayProductAfterClear();
var showWeeks=[];
$.post(evaPostUrl, { process: "getProductPriceList", urunKodu: v }, function (data){
if(data){
$.each(jQuery.parseJSON(data), function (index, value){
if(value.Onay&&dateBetweenCheck(value.BaslangicTarihi, value.BitisTarihi)){
if(value.MinHafta==value.MaxHafta&&jQuery.inArray(value.MaxHafta, showWeeks) < 0){
showWeeks.push(value.MaxHafta);
}}
});
let opC=0, opV="";
if(showWeeks.length > 0){
stayWeek.find("option").not(':first').remove();
stayWeek.find("option").eq(0).removeClass(cClass);
$.each(showWeeks, function (ind, val){
stayWeek.append("<option value='" + val + "'>" + val + " Hafta</option>");
opC++;
opV=val;
});
}else{
stayWeek.find("option").addClass(cClass);
stayWeek.find("option").eq(0).removeClass(cClass);
stayWeek.find("option").each(function (){
if(jQuery.isNumeric($(this).val())&&$(this).val() >=s.data("min-week")&&$(this).val() <=s.data("max-week")){
$(this).removeClass(cClass);
opC++;
opV=$(this).val();
}});
}
stayWeek.prop('disabled', false);
if(opC==1){
stayWeek.val(opV).change();
t.parents(".swiper-slide").removeClass("completed");
}else{
stayWeek.val("").change();
}
offerCheck();
}});
}else{
eduProductAfterClear();
}});
$(document).on("click", stayClass + " .product-list button", function (){
let btn=$(this), pi=btn.parents(".product-item"), trId=stayProduct.find(":selected").val();
if(offerStay.find("tr[data-id='" + trId + "']").length <=0){
btn.html("EKLENDİ");
offerStay.find("tbody").append("<tr data-id='" + stayProduct.find(":selected").val() + "' data-type='" + btn.data("type") + "' data-name='" + btn.data("name") + "' ><td>" + pi.find(".product-description").html() + "</td><td><button class='btn btn-danger btn-sm btn-delete'><i class='fa fa-times'></i></button></td></tr>");
stayProductList.find("button").addClass("disabled").attr("disabled", "disabled");
other.removeClass(cClass);
offerCheck();
offerSwiperGo(3);
}else{
eltAlert("Eklenemedi", "danger");
}});
$(document).on("click", otherClass + " .product-list button", function (){
let btn=$(this);
btn.html("EKLENDİ");
btn.addClass("disabled").attr("disabled", "disabled");
offerOther.find("tbody").append("<tr data-id='" + btn.data("id") + "' data-type='" + btn.data("type") + "' data-name='" + btn.data("name") + "'><td>" + btn.data("name") + "</td><td><button class='btn btn-danger btn-sm btn-delete'><i class='fa fa-times'></i></button></td></tr>");
offerCheck();
btn.parents(".swiper-slide").addClass("completed");
});
$(document).on("click", offerViewClass + " button.btn-delete", function (){
let t=$(this), d=t.parents(".table-responsive").parent("div"), tr=t.parents("tr");
if(d.hasClass("offerSchool")){
school.val("");
offerClear();
offerSwiperGo(0);
eduProduct.parents(".swiper-container").find(".swiper-slide").removeClass("completed");
}
else if(d.hasClass("offerEdu")){
eduProduct.val("");
eduWeekAfterClear();
eduProduct.prop('disabled', false);
eduProduct.parents(".swiper-slide").removeClass("completed");
stayProduct.parents(".swiper-slide").removeClass("completed");
offerSwiperGo(1);
offerOther.find("tbody").html("");
otherProductList.find("button").removeClass("disabled").prop("disabled", false).html("EKLE");
}
else if(d.hasClass("offerStay")){
stayWeekAfterClear();
stayProduct.val("").prop('disabled', false);
stayProduct.parents(".swiper-slide").removeClass("completed");
offerSwiperGo(2);
}
else if(d.hasClass("offerOther")){
otherProductList.find("button[data-id='" + tr.data("id") + "']").removeClass("disabled").prop("disabled", false).html("EKLE");
if(otherProductList.find("button.disabled").length <=0){
otherProductList.parents(".swiper-slide").removeClass("completed");
offerSwiperGo(3);
}}
tr.remove();
offerCheck();
});
$(document).on("click", "button.btn-offer-complete", function (){
let offerRequest={ "TeklifBilgileri": { "KursBaslangic": "", "KursHafta": 0, "KonaklamaBaslangic": "", "KonaklamaHafta": 0, "MerkezKodu": "", "Urunler": [] }, "KisiBilgileri": { "AdiSoyadi": "", "Telfon": "", "Mail": "", "Sehir": "", "UtmQuery": "" }};
let selectEduProduct=offerEdu.find("tbody > tr"), selectStayProduct=offerStay.find("tbody > tr"), selectOtherProducts=offerOther.find("tbody > tr");
offerRequest.TeklifBilgileri.KursBaslangic=selectEduProduct.find(".start span").text();
offerRequest.TeklifBilgileri.KursHafta=selectEduProduct.find(".week span").text();
offerRequest.TeklifBilgileri.KonaklamaBaslangic=selectStayProduct.find(".start span").text();
if(!offerRequest.TeklifBilgileri.KonaklamaBaslangic){
offerRequest.TeklifBilgileri.KonaklamaBaslangic=stayDate.val();
}
offerRequest.TeklifBilgileri.KonaklamaHafta=selectStayProduct.find(".week span").text();
if(!jQuery.isNumeric(offerRequest.TeklifBilgileri.KonaklamaHafta)){
offerRequest.TeklifBilgileri.KonaklamaHafta=stayWeek.val();
}
offerRequest.TeklifBilgileri.MerkezKodu=school.find(":selected").val();
offerRequest.TeklifBilgileri.Urunler.push({ "UrunTipi": selectEduProduct.data("type"), "UrunKodu": selectEduProduct.data("id"), "UrunAdi": selectEduProduct.data("name") });
offerRequest.TeklifBilgileri.Urunler.push({ "UrunTipi": selectStayProduct.data("type"), "UrunKodu": selectStayProduct.data("id"), "UrunAdi": selectStayProduct.data("name") });
selectOtherProducts.each(function (){
let t=$(this);
offerRequest.TeklifBilgileri.Urunler.push({ "UrunTipi": t.data("type"), "UrunKodu": t.data("id"), "UrunAdi": t.data("name") });
});
let e=0, uNameVal=uName.val(), uEmailVal=uEmail.val(), uCityVal=uCity.val(), uPhoneVal=uPhone.val();
if(uNameVal){
offerRequest.KisiBilgileri.AdiSoyadi=uNameVal;
}else{
e++;
eltAlert("Lütfen ad soyad giriniz.", "danger");
}
if(uEmailVal&&isEmail(uEmailVal)){
offerRequest.KisiBilgileri.Mail=uEmailVal;
}else{
e++;
eltAlert("Lütfen mail adresinizi giriniz.", "danger");
}
if(uPhoneVal&&isPhone(uPhoneVal)){
offerRequest.KisiBilgileri.Telfon=uPhoneVal;
}else{
e++;
eltAlert("Lütfen telefon numaranızı giriniz.", "danger");
}
if(uCityVal){
offerRequest.KisiBilgileri.Sehir=uCityVal;
if(uCityVal==34 ){
var xp=$("#offerCreate select#SubeKodu option:selected").val();
if(!xp){
e++;
eltAlert("Lütfen şube seçiniz.", "danger");
}else{
offerRequest.KisiBilgileri.Sube=xp;
}}
}else{
e++;
eltAlert("Lütfen şehrinizi seçiniz.", "danger");
}
if(!e){
offerRequest.KisiBilgileri.UtmQuery=$.cookie('first') + "|" + window.location.href;
$.post(evaPostLimitCheckUrl, { phone: offerRequest.KisiBilgileri.Telfon }, function (r){
if($.trim(r)=="yes"){
$.post(evaPostUrl, { process: "sendOfferUserInformation", values: offerRequest }, function (data){
$.post("https://eltedu.net/api/FiyatTeklifi/Getir", offerRequest).done(function (data){
if(data){
location.href="/fiyat-teklifi?id=" + data;
}else{
eltAlert("Hata oluştu.", "danger");
}});
});
}else{
eltAlert("Günlük teklif limitiniz dolmuştur. Yeni teklifler için danışmanımız size ulaşım sağlayacaktır", "danger");
}},"html");
}});
uPhone.change(function (){
let t=$(this), v=t.val();
if(isPhone(v)){
$.post(evaPostUrl, { process: "sendVerifyCode", phone: v }, function (data){
if(data=='"Doğrulandı"'){
phoneNumberCheck.addClass(cClass);
uPhone.addClass("verify");
offerLastStep.find("button").addClass("btn-offer-complete").removeClass("disabled").attr("disabled", false);
$('.btn-phoneNumberCheck-fake').text('DOĞRULANDI');
eltAlert("Telefon numaranız doğrulandı.", "success");
}
else if(data=='"Doğrulama Kodu Gönderildi."'){
phoneNumberCheck.removeClass(cClass);
uPhone.addClass("disabled").attr("disabled", "disabled");
phoneNumberCheck.find("span").html(v);
$(".btn-phoneNumberCheck-fake").remove();
eltAlert("Lütfen telefonunuza gelen doğrulama kodunu girerek numaranızı doğrulayınız.", "success");
}else{
uPhone.removeClass("disabled").attr("disabled", false);
phoneNumberCheck.addClass(cClass);
phoneNumberCheck.find(".userPhoneCode").val("");
eltAlert("Doğrulama kodu gönderilemedi.", "danger");
}}, "html");
}else{
phoneNumberCheck.addClass(cClass);
eltAlert("Lütfen geçerli bir telefon numarası giriniz.", "danger");
}});
$(".btn-phoneNumberCheck").click(function (){
let code=phoneNumberCheck.find(".userPhoneCode").val();
if(code){
$.post(evaPostUrl, { process: "verifyCode", phone: uPhone.val(), code: code }, function (data){
if(data=='"Onaylandı"'){
phoneNumberCheck.remove();
uPhone.addClass("verify");
offerLastStep.find("button").addClass("btn-offer-complete").removeClass("disabled").attr("disabled", false);
eltAlert("Telefon numaranız doğrulandı.", "success");
}else{
uPhone.removeClass("verify");
phoneNumberCheck.find(".userPhoneCode").val("");
eltAlert("Doğrulama kodu geçerli değil.", "danger");
}}, "html");
}else{
eltAlert("Lütfen telefonunuza gelen doğrulama kodunu giriniz.", "danger");
}});
uEmail.change(function (){
let t=$(this), v=t.val();
if(!isEmail(v)){
eltAlert("Lütfen geçerli bir mail adresi giriniz.", "danger");
}});
});
function dateBetweenCheck(fDate, lDate){
let cDate=Date.now();
fDate=new Date(fDate).valueOf();
lDate=new Date(lDate).valueOf();
if( cDate <=lDate){
return true;
}else{
return false;
}};