templates\menu\vue\index-script.html.twig line 1

Open in your IDE?
  1. <script src="https://unpkg.com/vue@3"></script>
  2. <script src="https://unpkg.com/vue-router@4"></script>
  3. <script>
  4.     /*-
  5.     const routes = [{path: '/', component: Menu, name: 'menu'}]
  6.     const router = new VueRouter({
  7.         mode: 'history', base: '/menu/', routes
  8.     })
  9.      */
  10.     //-Vue.use(VueRouter)
  11.     let app = Vue.createApp({
  12.         delimiters: ['${', '}'],
  13.         data() {
  14.             return {
  15.                 food_config: {},
  16.                 isLoading: false,
  17.                 modified: false,  // kullanıcı menüde değişiklik yaptı mı?
  18.                 showLimit: true,   // Aylık yemek limitleri panelini göster
  19.                 limitLeft: false,  // Aylık yemek limitleri paneli sol-alt köşede
  20.                 grupLimitAsimi: false,
  21.                 filter: {
  22.                     yil: 2022,
  23.                     ay: 1,
  24.                     ogun: 1,
  25.                     turu: 'NORMAL',
  26.                     canEdit: false
  27.                 },
  28.                 menu: [],
  29.                 menu_kontrol: [],
  30.                 grupLimit: [],
  31.                 aylar: [{value: 1, text: "OCAK"}, {value: 2, text: "ŞUBAT"}, {value: 3, text: "MART"},
  32.                     {value: 4, text: "NİSAN"}, {value: 5, text: "MAYIS"}, {value: 6, text: "HAZİRAN"},
  33.                     {value: 7, text: "TEMMUZ"}, {value: 8, text: "AĞUSTOS"}, {value: 9, text: "EYLÜL"},
  34.                     {value: 10, text: "EKİM"}, {value: 11, text: "KASIM"}, {value: 12, text: "ARALIK"}],
  35.                 ogunler: [{value: 1, text: "ÖĞLE"}, {value: 2, text: "AKŞAM"}, {value: 3, text: "GECE"}],
  36.                 turler: ["NORMAL", "KAHVALTI", "KUMANYA", "DİYET", "SALATBAR", "MESAİ", "PAKET"]
  37.             }
  38.         },
  39.         methods: {
  40.             getMenu() {
  41.                 this.isLoading = true;
  42.                 this.menu = [];
  43.                 this.filter.canEdit = false;
  44.                 let params = '';
  45.                 if (this.filter.yil != null)
  46.                     params = '?yil=' + this.filter.yil + '&ay=' + this.filter.ay + '&ogun=' + this.filter.ogun + '&turu=' + this.filter.turu;
  47.                 axios.get('/api/menu/' + params)
  48.                     .then(response => {
  49.                         try {
  50.                             if (response.data.menu[0].length <= 1) {
  51.                                 console.log("Tanımlı menü bulunamadı!", response.data)
  52.                                 throw "Seçilen dönem için henüz menü tanımlanmamış!";
  53.                             }
  54.                             this.menu = response.data.menu;
  55.                             this.menu_kontrol = response.data.menu_kontrol;
  56.                             this.grupLimit = response.data.grup_limit;
  57.                             this.filter.canEdit = response.data.filter.canEdit;
  58.                             this.isLoading = false;
  59.                             this.grupToplamiGuncelle(0, 0, undefined);
  60.                             this.modified = false;
  61.                         } catch (error) {
  62.                             console.log(error)
  63.                             alert("Menü yüklenirken oluştu:\n\n" + error);
  64.                             this.isLoading = false;
  65.                         }
  66.                     })
  67.                     .catch(error => {
  68.                         console.log(error)
  69.                         alert("Menü alınırken hata oluştu:\n" + error);
  70.                     })
  71.                     .finally(() => this.isLoading = false)
  72.             },
  73.             menuKaydet() {
  74.                 if (this.grupLimitAsimi) {
  75.                     alert("Limit aşımı var!");
  76.                     return false;
  77.                 }
  78.                 this.filter.canEdit = false;
  79.                 axios.post("/api/menu/save", {'menu': this.menu, 'filter': this.filter}
  80.                     // , {'headers': {"Content-Type": "application/x-www-form-urlencoded"}}
  81.                 )
  82.                     .then(response => {
  83.                         this.filter.canEdit = true;
  84.                         if (response.data.success) {
  85.                             this.modified = false;
  86.                             alert("Güncellemeler kaydedildi...");
  87.                         } else {
  88.                             console.log("Güncellemeler kaydedilirken hata oluştu:\n\n" + JSON.stringify(response.data));
  89.                             alert("Güncellemeler kaydedilirken hata oluştu:\n\n" + JSON.stringify(response.data));
  90.                         }
  91.                         // location.reload();
  92.                     })
  93.                     .catch(error => {
  94.                         console.log(error);
  95.                         this.canEdit = true;
  96.                         alert("Güncellemeler kaydedilirken ağ hatası hata oluştu!");
  97.                         // location.reload();
  98.                     });
  99.             },
  100.             /**
  101.              * ÖĞLE için seçilen yemek MESAİ'de de var mı kontrolü yapar
  102.              * @param satir Hafta numarası (1, 2, 3 ...)
  103.              * @param gun Haftanın günü (1..7)
  104.              * @param rec_kodu Seçilen yemeğin kodu
  105.              * @param cinsi2 Sadece 'ANA YEMEK1' olanlar için kotrol yapar
  106.              */
  107.             cakisanYemekKontrolu(satir, gun, rec_kodu, cinsi2) {
  108.                 if ((rec_kodu === undefined) || (cinsi2 != 'ANA YEMEK1')) return;
  109.                 for (let ogun in this.menu_kontrol) {
  110.                     try {
  111.                         for (let yemek = 0; yemek < this.menu_kontrol[ogun][satir][gun].length; yemek++) {
  112.                             if ((this.menu_kontrol[ogun][satir][gun][yemek].CINSI2 == 'ANA YEMEK1') && (this.menu_kontrol[ogun][satir][gun][yemek].RECKODU == rec_kodu)) {
  113.                                 console.error("ÇAKIŞMA: ", ogun, rec_kodu);
  114.                                 alert("Aynı yemek " + ogun + " menüsünde de tanımlanmış!");
  115.                             }
  116.                         }
  117.                     } catch (error) {
  118.                         console.warn('ÇAKIŞMA ERROR', error);
  119.                     }
  120.                 }
  121.             },
  122.             /**
  123.              * Uyumsuz alternatif yemek seçimine izin vermez
  124.              * @param satir Hafta numarası (1, 2, 3 ...)
  125.              * @param gun Haftanın günü (1..7)
  126.              * @param rec_kodu Seçilen yemeğin kodu
  127.              */
  128.             uyumsuzYemekKontrolu(satir, gun, rec_kodu) {
  129.                 if (rec_kodu === undefined) return;
  130.                 for (let yemek in this.menu[satir][gun]) {
  131.                     for (let uyumsuz in this.menu[satir][gun][yemek].UYUMSUZ) {
  132.                         if (rec_kodu == this.menu[satir][gun][yemek].UYUMSUZ[uyumsuz].RECKODU) {
  133.                             try {
  134.                                 console.warn("UYUMSUZ YEMEK: ", this.menu[satir][gun][yemek].RECADI, this.menu[satir][gun][yemek].UYUMSUZ[uyumsuz].RECETEADI);
  135.                                 alert("UYUMSUZ YEMEK: \n\n" + this.menu[satir][gun][yemek].RECADI + "  <--->  " + this.menu[satir][gun][yemek].UYUMSUZ[uyumsuz].RECETEADI);
  136.                                 //*alert("Aynı yemek " + ogun + " menüsünde de tanımlanmış!");
  137.                             } catch (e) {
  138.                                 console.error('Uyumsuz yemek kontrolünde İSTİSNA!');
  139.                             }
  140.                         }
  141.                     }
  142.                 }
  143.             },
  144.             /**
  145.              * Seçilen yemek aynı gün zaten var mı kontrolü yapar
  146.              * @param satir Hafta numarası (1, 2, 3 ...)
  147.              * @param gun Haftanın günü (1..7)
  148.              * @param rec_kodu Seçilen yemeğin kodu
  149.              */
  150.             ciftYemekKontrolu(satir, gun, rec_kodu) {
  151.                 if (rec_kodu === undefined) return;
  152.                 let adet=-1;
  153.                 try {
  154.                     for (let yemek = 0; yemek < this.menu[satir][gun].length; yemek++) {
  155.                         if (this.menu[satir][gun][yemek].RECKODU == rec_kodu) {
  156.                             adet++;
  157.                             if(adet > 0) {
  158.                                 console.error("ÇİFT: ", satir, gun, rec_kodu);
  159.                                 alert("Aynı yemek bugün için zaten tanımlanmış!\n" +
  160.                                     this.menu[satir][gun][yemek].RECKODU + " : " + this.menu[satir][gun][yemek].RECADI);
  161.                                 break;
  162.                             }
  163.                         }
  164.                     }
  165.                 } catch (error) {
  166.                     console.warn('ÇİFT YEMEK', error);
  167.                 }
  168.             },
  169.             grupToplamiGuncelle(satir, gun, rec_kodu, cinsi2) {
  170.                 this.modified = true;
  171.                 // Yemek türleri için sınır tanımlanmamışsa çık
  172.                 //***  if (this.grupLimit.length <= 0) return;
  173.                 // Tüm toplamları sıfırla
  174.                 for (let g in this.grupLimit) {
  175.                     this.grupLimit[g].TOPLAM = 0;
  176.                 }
  177.                 for (let satir = 0; satir < this.menu.length; satir++) {
  178.                     for (let gun = 0; gun < this.menu[satir].length; gun++) {
  179.                         for (let yemek = 0; yemek < this.menu[satir][gun].length; yemek++) {
  180.                             if (this.menu[satir][gun][yemek].CINSI) {
  181.                                 let grup = this.menu[satir][gun][yemek].CINSI;
  182.                                 if (this.menu[satir][gun][yemek].ALTERNATIF) {
  183.                                     for (let a = 0; a < this.menu[satir][gun][yemek].ALTERNATIF.length; a++) {
  184.                                         if (this.menu[satir][gun][yemek].ALTERNATIF[a].RECKODU == this.menu[satir][gun][yemek].RECKODU) {
  185.                                             grup = this.menu[satir][gun][yemek].ALTERNATIF[a].CINSI;
  186.                                             this.menu[satir][gun][yemek].CINSI = grup;
  187.                                             let tmp = this.menu[satir][gun][yemek].ALTERNATIF[a].CINSI2;
  188.                                             this.menu[satir][gun][yemek].CINSI2 = tmp;
  189.                                             tmp = this.menu[satir][gun][yemek].ALTERNATIF[a].RECADI;
  190.                                             this.menu[satir][gun][yemek].RECADI = tmp;
  191.                                             break;
  192.                                         }
  193.                                     }
  194.                                 }
  195.                                 if (this.grupLimit[grup])
  196.                                     this.grupLimit[grup].TOPLAM++;
  197.                             }
  198.                         }
  199.                     }
  200.                 }
  201.                 this.grupLimitAsimi = false;
  202.                 for (let g in this.grupLimit) {
  203.                     if (this.grupLimit[g].MAXADET < this.grupLimit[g].TOPLAM) {
  204.                         this.grupLimitAsimi = true;
  205.                         break;
  206.                     }
  207.                 }
  208.                 this.uyumsuzYemekKontrolu(satir, gun, rec_kodu);
  209.                 this.cakisanYemekKontrolu(satir, gun, rec_kodu, cinsi2);
  210.                 this.ciftYemekKontrolu(satir, gun, rec_kodu);
  211.             },
  212.             exportMenu2Excel() {
  213.                 if (this.modified) {
  214.                     alert("Menüde değişiklik yapılmış.\nDevam etmeden önce değişiklikleri kaydetmelisiniz.");
  215.                     return;
  216.                 }
  217.                 // this.$router.push({
  218.                 //   path: '/menu/excel',
  219.                 //   params: this.filter
  220.                 // });
  221.                 const ret = [];
  222.                 for (let d in this.filter) {
  223.                     if (typeof this.filter[d] === 'object' || typeof this.filter[d] === 'array') {
  224.                         for (let arrD in this.filter[d]) {
  225.                             ret.push(`${encodeURIComponent(d)}[]=${encodeURIComponent(this.filter[d][arrD])}`)
  226.                         }
  227.                     } else if (typeof this.filter[d] === 'null' || typeof this.filter[d] === 'undefined') {
  228.                         ret.push(encodeURIComponent(d))
  229.                     } else {
  230.                         ret.push(`${encodeURIComponent(d)}=${encodeURIComponent(this.filter[d])}`)
  231.                     }
  232.                 }
  233.                 window.location.assign("/api/menu/excel?" + ret.join('&'));
  234.             }
  235.         },
  236.         mounted() {
  237.             //-this.food_config = JSON.parse(this.$el.attributes['data-config'].value);
  238.             let bugun = new Date();
  239.             /*if (bugun.getMonth() == 11) {
  240.                 this.filter.yil = bugun.getFullYear() + 1;
  241.                 this.filter.ay = 0;
  242.             } else {
  243.                 this.filter.yil = bugun.getFullYear();
  244.                 this.filter.ay = bugun.getMonth() + 2;
  245.             }*/
  246.             this.filter.yil = bugun.getFullYear();
  247.             this.filter.ay = bugun.getMonth() + 1;
  248.             this.filter.ogun = 1;
  249.             this.filter.turu = 'NORMAL';
  250.             // Sayfa açılır açılmaz menünün yüklenmesi isteniyorsa sonraki satır açılabilir
  251.             //- this.getMenu();
  252.         },
  253.         //-router
  254.     });
  255.     app.mount('#app')
  256. </script>