<script src="https://unpkg.com/vue@3"></script>
<script src="https://unpkg.com/vue-router@4"></script>
<script>
/*-
const routes = [{path: '/', component: Menu, name: 'menu'}]
const router = new VueRouter({
mode: 'history', base: '/menu/', routes
})
*/
//-Vue.use(VueRouter)
let app = Vue.createApp({
delimiters: ['${', '}'],
data() {
return {
food_config: {},
isLoading: false,
modified: false, // kullanıcı menüde değişiklik yaptı mı?
showLimit: true, // Aylık yemek limitleri panelini göster
limitLeft: false, // Aylık yemek limitleri paneli sol-alt köşede
grupLimitAsimi: false,
filter: {
yil: 2022,
ay: 1,
ogun: 1,
turu: 'NORMAL',
canEdit: false
},
menu: [],
menu_kontrol: [],
grupLimit: [],
aylar: [{value: 1, text: "OCAK"}, {value: 2, text: "ŞUBAT"}, {value: 3, text: "MART"},
{value: 4, text: "NİSAN"}, {value: 5, text: "MAYIS"}, {value: 6, text: "HAZİRAN"},
{value: 7, text: "TEMMUZ"}, {value: 8, text: "AĞUSTOS"}, {value: 9, text: "EYLÜL"},
{value: 10, text: "EKİM"}, {value: 11, text: "KASIM"}, {value: 12, text: "ARALIK"}],
ogunler: [{value: 1, text: "ÖĞLE"}, {value: 2, text: "AKŞAM"}, {value: 3, text: "GECE"}],
turler: ["NORMAL", "KAHVALTI", "KUMANYA", "DİYET", "SALATBAR", "MESAİ", "PAKET"]
}
},
methods: {
getMenu() {
this.isLoading = true;
this.menu = [];
this.filter.canEdit = false;
let params = '';
if (this.filter.yil != null)
params = '?yil=' + this.filter.yil + '&ay=' + this.filter.ay + '&ogun=' + this.filter.ogun + '&turu=' + this.filter.turu;
axios.get('/api/menu/' + params)
.then(response => {
try {
if (response.data.menu[0].length <= 1) {
console.log("Tanımlı menü bulunamadı!", response.data)
throw "Seçilen dönem için henüz menü tanımlanmamış!";
}
this.menu = response.data.menu;
this.menu_kontrol = response.data.menu_kontrol;
this.grupLimit = response.data.grup_limit;
this.filter.canEdit = response.data.filter.canEdit;
this.isLoading = false;
this.grupToplamiGuncelle(0, 0, undefined);
this.modified = false;
} catch (error) {
console.log(error)
alert("Menü yüklenirken oluştu:\n\n" + error);
this.isLoading = false;
}
})
.catch(error => {
console.log(error)
alert("Menü alınırken hata oluştu:\n" + error);
})
.finally(() => this.isLoading = false)
},
menuKaydet() {
if (this.grupLimitAsimi) {
alert("Limit aşımı var!");
return false;
}
this.filter.canEdit = false;
axios.post("/api/menu/save", {'menu': this.menu, 'filter': this.filter}
// , {'headers': {"Content-Type": "application/x-www-form-urlencoded"}}
)
.then(response => {
this.filter.canEdit = true;
if (response.data.success) {
this.modified = false;
alert("Güncellemeler kaydedildi...");
} else {
console.log("Güncellemeler kaydedilirken hata oluştu:\n\n" + JSON.stringify(response.data));
alert("Güncellemeler kaydedilirken hata oluştu:\n\n" + JSON.stringify(response.data));
}
// location.reload();
})
.catch(error => {
console.log(error);
this.canEdit = true;
alert("Güncellemeler kaydedilirken ağ hatası hata oluştu!");
// location.reload();
});
},
/**
* ÖĞLE için seçilen yemek MESAİ'de de var mı kontrolü yapar
* @param satir Hafta numarası (1, 2, 3 ...)
* @param gun Haftanın günü (1..7)
* @param rec_kodu Seçilen yemeğin kodu
* @param cinsi2 Sadece 'ANA YEMEK1' olanlar için kotrol yapar
*/
cakisanYemekKontrolu(satir, gun, rec_kodu, cinsi2) {
if ((rec_kodu === undefined) || (cinsi2 != 'ANA YEMEK1')) return;
for (let ogun in this.menu_kontrol) {
try {
for (let yemek = 0; yemek < this.menu_kontrol[ogun][satir][gun].length; yemek++) {
if ((this.menu_kontrol[ogun][satir][gun][yemek].CINSI2 == 'ANA YEMEK1') && (this.menu_kontrol[ogun][satir][gun][yemek].RECKODU == rec_kodu)) {
console.error("ÇAKIŞMA: ", ogun, rec_kodu);
alert("Aynı yemek " + ogun + " menüsünde de tanımlanmış!");
}
}
} catch (error) {
console.warn('ÇAKIŞMA ERROR', error);
}
}
},
/**
* Uyumsuz alternatif yemek seçimine izin vermez
* @param satir Hafta numarası (1, 2, 3 ...)
* @param gun Haftanın günü (1..7)
* @param rec_kodu Seçilen yemeğin kodu
*/
uyumsuzYemekKontrolu(satir, gun, rec_kodu) {
if (rec_kodu === undefined) return;
for (let yemek in this.menu[satir][gun]) {
for (let uyumsuz in this.menu[satir][gun][yemek].UYUMSUZ) {
if (rec_kodu == this.menu[satir][gun][yemek].UYUMSUZ[uyumsuz].RECKODU) {
try {
console.warn("UYUMSUZ YEMEK: ", this.menu[satir][gun][yemek].RECADI, this.menu[satir][gun][yemek].UYUMSUZ[uyumsuz].RECETEADI);
alert("UYUMSUZ YEMEK: \n\n" + this.menu[satir][gun][yemek].RECADI + " <---> " + this.menu[satir][gun][yemek].UYUMSUZ[uyumsuz].RECETEADI);
//*alert("Aynı yemek " + ogun + " menüsünde de tanımlanmış!");
} catch (e) {
console.error('Uyumsuz yemek kontrolünde İSTİSNA!');
}
}
}
}
},
/**
* Seçilen yemek aynı gün zaten var mı kontrolü yapar
* @param satir Hafta numarası (1, 2, 3 ...)
* @param gun Haftanın günü (1..7)
* @param rec_kodu Seçilen yemeğin kodu
*/
ciftYemekKontrolu(satir, gun, rec_kodu) {
if (rec_kodu === undefined) return;
let adet=-1;
try {
for (let yemek = 0; yemek < this.menu[satir][gun].length; yemek++) {
if (this.menu[satir][gun][yemek].RECKODU == rec_kodu) {
adet++;
if(adet > 0) {
console.error("ÇİFT: ", satir, gun, rec_kodu);
alert("Aynı yemek bugün için zaten tanımlanmış!\n" +
this.menu[satir][gun][yemek].RECKODU + " : " + this.menu[satir][gun][yemek].RECADI);
break;
}
}
}
} catch (error) {
console.warn('ÇİFT YEMEK', error);
}
},
grupToplamiGuncelle(satir, gun, rec_kodu, cinsi2) {
this.modified = true;
// Yemek türleri için sınır tanımlanmamışsa çık
//*** if (this.grupLimit.length <= 0) return;
// Tüm toplamları sıfırla
for (let g in this.grupLimit) {
this.grupLimit[g].TOPLAM = 0;
}
for (let satir = 0; satir < this.menu.length; satir++) {
for (let gun = 0; gun < this.menu[satir].length; gun++) {
for (let yemek = 0; yemek < this.menu[satir][gun].length; yemek++) {
if (this.menu[satir][gun][yemek].CINSI) {
let grup = this.menu[satir][gun][yemek].CINSI;
if (this.menu[satir][gun][yemek].ALTERNATIF) {
for (let a = 0; a < this.menu[satir][gun][yemek].ALTERNATIF.length; a++) {
if (this.menu[satir][gun][yemek].ALTERNATIF[a].RECKODU == this.menu[satir][gun][yemek].RECKODU) {
grup = this.menu[satir][gun][yemek].ALTERNATIF[a].CINSI;
this.menu[satir][gun][yemek].CINSI = grup;
let tmp = this.menu[satir][gun][yemek].ALTERNATIF[a].CINSI2;
this.menu[satir][gun][yemek].CINSI2 = tmp;
tmp = this.menu[satir][gun][yemek].ALTERNATIF[a].RECADI;
this.menu[satir][gun][yemek].RECADI = tmp;
break;
}
}
}
if (this.grupLimit[grup])
this.grupLimit[grup].TOPLAM++;
}
}
}
}
this.grupLimitAsimi = false;
for (let g in this.grupLimit) {
if (this.grupLimit[g].MAXADET < this.grupLimit[g].TOPLAM) {
this.grupLimitAsimi = true;
break;
}
}
this.uyumsuzYemekKontrolu(satir, gun, rec_kodu);
this.cakisanYemekKontrolu(satir, gun, rec_kodu, cinsi2);
this.ciftYemekKontrolu(satir, gun, rec_kodu);
},
exportMenu2Excel() {
if (this.modified) {
alert("Menüde değişiklik yapılmış.\nDevam etmeden önce değişiklikleri kaydetmelisiniz.");
return;
}
// this.$router.push({
// path: '/menu/excel',
// params: this.filter
// });
const ret = [];
for (let d in this.filter) {
if (typeof this.filter[d] === 'object' || typeof this.filter[d] === 'array') {
for (let arrD in this.filter[d]) {
ret.push(`${encodeURIComponent(d)}[]=${encodeURIComponent(this.filter[d][arrD])}`)
}
} else if (typeof this.filter[d] === 'null' || typeof this.filter[d] === 'undefined') {
ret.push(encodeURIComponent(d))
} else {
ret.push(`${encodeURIComponent(d)}=${encodeURIComponent(this.filter[d])}`)
}
}
window.location.assign("/api/menu/excel?" + ret.join('&'));
}
},
mounted() {
//-this.food_config = JSON.parse(this.$el.attributes['data-config'].value);
let bugun = new Date();
/*if (bugun.getMonth() == 11) {
this.filter.yil = bugun.getFullYear() + 1;
this.filter.ay = 0;
} else {
this.filter.yil = bugun.getFullYear();
this.filter.ay = bugun.getMonth() + 2;
}*/
this.filter.yil = bugun.getFullYear();
this.filter.ay = bugun.getMonth() + 1;
this.filter.ogun = 1;
this.filter.turu = 'NORMAL';
// Sayfa açılır açılmaz menünün yüklenmesi isteniyorsa sonraki satır açılabilir
//- this.getMenu();
},
//-router
});
app.mount('#app')
</script>