Anons79 Mini Shell

Directory : /home/aplikasiposinfo/public_html/demo2.fixmate.id/resources/views/service/
Upload File :
Current File : /home/aplikasiposinfo/public_html/demo2.fixmate.id/resources/views/service/script.blade.php

    <script>
        const tableSparepart = document.getElementById('table-sparepart');
        const tableSparepartShow = document.getElementById('table-sparepart-list');
        const tableDetail = document.getElementById('table-detail-sparepart');
        const itemDeleteButton = document.querySelectorAll(".item-delete");
        const pelangganIdSelect = document.querySelector("#pelanggan_id");
        const pelangganForm = document.querySelector("#form_pelanggan");
        const pencarian = document.getElementById("cari");
        const itemDiskonInput = document.querySelectorAll(".item-diskon");
        const itemDiskonPersenInput = document.querySelectorAll(".item-diskon-persen");
        const inputBiaya = document.getElementById("biaya");
        const itemQtyInput = document.querySelectorAll(".qty");
        const numberFormat = new Intl.NumberFormat({
            style: 'currency'
        });

        let detailArray = [];



        function loadList() {
            const nilaiPencarian = pencarian.value;
            fetch("{{ route('get-item-sparepart') }}?cari=" + nilaiPencarian, {
                    method: "GET"
                })
                .then(
                    (response) => {
                        return response.json();
                    }
                )
                .then((data) => {
                    const rowCount = tableSparepart.querySelector('tbody');

                    while (rowCount.firstChild) {
                        rowCount.removeChild(rowCount.firstChild);
                    }

                    let items = data;

                    items.data.forEach(item => {
                        let namaSparepartText = document.createTextNode(item.nama_item);
                        let hargaJualText = document.createTextNode(numberFormat.format(item
                            .harga_item));
                        let hargaBeliText = document.createTextNode(numberFormat.format(item
                            .biaya_item));
                        // let stokText = document.createTextNode(item.stok);
                        let stok_tokos = item.stok_item_tokos.filter(toko => toko.toko_id == document
                            .getElementById("toko_id").value);
                        var itemStok = item.stok_item_tokos.length > 0 ? stok_tokos.reduce((sum, toko) => sum +
                            toko.stok, 0) : item.stok;
                        let stokText = document.createTextNode(itemStok);

                        let pilihButtonText = document.createTextNode(`Pilih`);

                        let pilihButton = document.createElement("button");
                        pilihButton.classList.add('btn', 'btn-primary', 'item-add');
                        // pilihButton.setAttribute('data-id', item.id);
                        pilihButton.setAttribute('type', "button");
                        pilihButton.dataset.id = item.id;
                        pilihButton.appendChild(pilihButtonText);

                        let jumlahInput = document.createElement("input");
                        jumlahInput.setAttribute('type', "number");
                        jumlahInput.setAttribute('value', 0);
                        if (itemStok == null || itemStok < 0) {
                            jumlahInput.setAttribute('max', 0);
                        } else {
                            jumlahInput.setAttribute('max', itemStok);
                        }
                        jumlahInput.setAttribute('min', 0);
                        jumlahInput.classList.add('form-control', 'jumlah-input');

                        if (itemStok == null || itemStok <= 0) {
                            jumlahInput.setAttribute('disabled', true);
                            jumlahInput.setAttribute('title', "Stok Habis!")
                            pilihButton.setAttribute('disabled', true);
                            pilihButton.setAttribute('title', "Stok Habis!")
                        }



                        let row = tableSparepart.querySelector("tbody").insertRow(-1);
                        let namaSparepart = row.insertCell(0);
                        let hargaBeli = row.insertCell(1);
                        let hargaJual = row.insertCell(2);

                        let stok = row.insertCell(3);
                        let jumlah = row.insertCell(4);
                        let pilih = row.insertCell(5);

                        if (window.innerWidth < 768) {
                            namaSparepart.setAttribute('style', 'width: 150px;')
                        } else {
                            namaSparepart.setAttribute('style', 'max-width: 150px;')
                        }


                        namaSparepart.appendChild(namaSparepartText);
                        hargaJual.appendChild(hargaJualText);
                        hargaBeli.appendChild(hargaBeliText);
                        stok.appendChild(stokText);
                        jumlah.appendChild(jumlahInput);
                        pilih.appendChild(pilihButton);

                        addEventPilih(pilihButton);
                    });
                });

        }



        tableSparepartShow.addEventListener("click", function() {
            loadList();
            pencarian.addEventListener('input', function() {
                // Mengambil nilai input pencarian

                loadList();

            });


        });

        //memunculkan data pada modal table item

        //menambahkan item ke dalam detail penjualan
        function addEventPilih(element) {
            element.addEventListener('click', function(event) {



                let jumlah = this.parentElement.parentElement.childNodes[4];

                let jumlahValue = jumlah.querySelector(".jumlah-input").value;

                fetch("{{ route('get-item') }}?search=" + this.dataset.id, {
                        method: "GET"
                    })
                    .then(
                        (response) => {
                            return response.json();
                        }
                    )
                    .then((data) => {

                        let items = data;
                        items.data.forEach(item => {
                            if (jumlahValue > 0) {
                                addDetailBarangRow();
                            }

                            function addDetailBarangRow() {
                                showAlert(item.nama_item);

                                //new text element
                                let namaSparepartText = document.createTextNode(item.nama_item);
                                let hargaJualText = document.createTextNode(numberFormat.format(item
                                    .harga_item));
                                let hargaBeliText = document.createTextNode(numberFormat.format(item
                                    .biaya_item));
                                let jumlahText = document.createTextNode(jumlahValue);
                                let subTotalText = document.createTextNode(numberFormat.format(item
                                    .harga_item * jumlahValue));
                                let hapusButtonText = document.createTextNode("X");

                                let hapusButton = document.createElement("button");
                                hapusButton.classList.add("btn", "btn-danger", "item-delete");
                                hapusButton.appendChild(hapusButtonText);
                                hapusButton.setAttribute('type', "button");

                                let diskonInput = document.createElement("input");
                                diskonInput.classList.add("item-diskon");
                                diskonInput.setAttribute("name", "diskon_item[]");
                                diskonInput.setAttribute("type", "number");
                                diskonInput.setAttribute("min", 0);
                                diskonInput.setAttribute("value", 0);

                                let stok_tokos = item.stok_item_tokos.filter(toko => toko.toko_id ==
                                    document.getElementById("toko_id").value);
                                var itemStok = item.stok_item_tokos.length > 0 ? stok_tokos.reduce((sum,
                                    toko) => sum + toko.stok, 0) : item.stok;


                                //hidden input for form request
                                let jumlahInput = document.createElement("input");
                                jumlahInput.classList.add("qty");
                                jumlahInput.setAttribute('name', "jumlah[]");
                                jumlahInput.setAttribute('type', "number");
                                jumlahInput.setAttribute('max', itemStok);
                                jumlahInput.setAttribute('min', 0);
                                jumlahInput.setAttribute('value', jumlahValue);
                                // jumlahInput.setAttribute('hidden', true);

                                //hidden input for form request
                                let idInput = document.createElement("input");
                                idInput.setAttribute('name', "id[]");
                                idInput.classList.add("item_id");
                                idInput.setAttribute('type', "text");
                                idInput.setAttribute('value', item.id);
                                idInput.setAttribute('hidden', true);

                                let namaInput = document.createElement("input");
                                namaInput.setAttribute('name', "nama_item[]");
                                namaInput.classList.add("nama_item");
                                namaInput.setAttribute('type', "text");
                                namaInput.setAttribute('value', item.nama_item);
                                namaInput.setAttribute('hidden', true);

                                let hargaInput = document.createElement("input");
                                hargaInput.setAttribute('name', "harga[]");
                                hargaInput.classList.add("harga");
                                hargaInput.setAttribute('type', "number");
                                hargaInput.setAttribute('value', item.harga_item);
                                hargaInput.setAttribute('hidden', true);

                                let biayaInput = document.createElement("input");
                                biayaInput.setAttribute('name', "biaya_item[]");
                                biayaInput.classList.add("biaya");
                                biayaInput.setAttribute('type', "number");
                                biayaInput.setAttribute('value', item.biaya_item);
                                biayaInput.setAttribute('hidden', true);

                                let row = tableDetail.querySelector("tbody").insertRow(-1);
                                let namaSparepart = row.insertCell(0);
                                let hargaBeli = row.insertCell(1);
                                let jumlah = row.insertCell(2);
                                let hargaJual = row.insertCell(3);
                                let subTotal = row.insertCell(4);
                                subTotal.classList.add("subTotal");
                                let hapus = row.insertCell(5);

                                namaSparepart.appendChild(namaSparepartText);
                                hargaJual.appendChild(hargaJualText);
                                hargaBeli.appendChild(diskonInput);
                                subTotal.appendChild(subTotalText);
                                // jumlah.appendChild(jumlahText);
                                jumlah.appendChild(jumlahInput);
                                jumlah.appendChild(idInput);
                                jumlah.appendChild(hargaInput);
                                jumlah.appendChild(namaInput);
                                jumlah.appendChild(biayaInput);
                                hapus.appendChild(hapusButton);

                                let detail = [item.id, jumlahValue];

                                addEventHapus(hapusButton);
                                addEventDiskon(diskonInput);
                                addEventQty(jumlahInput);
                                countGrandTotal();

                            }
                        });
                    });


            })
        }

        function showAlert(item) {

            alert(item + " Ditambahkan");


        }
        inputBiaya.addEventListener('input', function() {
            // Mengambil nilai input pencarian

            countGrandTotal();

        });

        function addEventHapus(element) {
            element.addEventListener("click", function(event) {
                this.parentElement.parentElement.remove();
                countGrandTotal();
            });
        }

        function addEventDiskon(e) {
            countSubTotal(e);
        }

        function addEventQty(e) {
            countSubTotal(e);
        }

        itemDeleteButton.forEach((e) => {
            e.addEventListener("click", function(event) {
                this.parentElement.parentElement.remove();
                countGrandTotal();
            });
        });

        itemDiskonInput.forEach((e) => {

            countSubTotal(e);
        });

        itemDiskonPersenInput.forEach((e) => {

            countSubTotal(e);
        });

        itemQtyInput.forEach((e) => {
            countSubTotal(e);
        });



        function countSubTotal(e) {
            e.addEventListener("input", function(event) {


                let qty = this.parentElement.parentElement.children[2].children[0];
                let hargaItem = this.parentElement.parentElement.children[3];
                let subTotalElement = this.parentElement.parentElement.children[4];
                let diskonInput = this.parentElement.parentElement.children[1].children[0];

                const harga = this.parentElement.parentElement.children[2].children[2];

                let hargaDiskon = Math.max(parseFloat(harga.value) - diskonInput.value, 0);

                // hargaItem.textContent = hargaDiskon;

                let subtotal = hargaDiskon * qty.value;

                subTotalElement.textContent = numberFormat.format(subtotal);

                countGrandTotal();
            });
        }


        function countGrandTotal() {
            let subTotal = document.querySelectorAll(".subTotal");
            let grandTotal = document.querySelector("#grandTotal");
            let inputgrandTotal = document.getElementById("input_grandTotal");

            let grandTotalValue = 0;
            let kembaliValue = 0;
            subTotal.forEach((element) => {

                subTotalValue1 = element.textContent.replaceAll(",", "");
                subTotalValue = parseFloat(subTotalValue1.replaceAll(".", ""));
                grandTotalValue += subTotalValue;


            });

            var biaya = inputBiaya.value.replace(/\D/g, '');


            // Mengonversi string menjadi integer
            var intBiaya = parseInt(biaya);

            grandTotalValue = grandTotalValue + intBiaya;

            let diskon_total = document.getElementById("diskon_total");
            let diskon_persen_total = document.getElementById("diskon_persen_total");
            let diskon_poin = document.getElementById("diskon_poin");


            if (diskon_total.value > 0) {
                grandTotalValue = grandTotalValue - diskon_total.value;
            }
            if (diskon_persen_total.value > 0) {
                grandTotalValue = grandTotalValue - ((diskon_persen_total.value / 100) * grandTotalValue)
                console.log(grandTotalValue);
            }

            if (diskon_poin.value > 0) {
                grandTotalValue = grandTotalValue - diskon_poin.value;
            }



            if (inputBiaya.value == '') {
                grandTotal.textContent = "Isi biaya Service terlebih dahulu !";
            } else {
                grandTotal.textContent = "Rp. " + numberFormat.format(grandTotalValue);
                inputgrandTotal.value = grandTotalValue;
            }


        }
        countGrandTotal();
    </script>
    <script>
        function kirim() {
            // form modal
            const namaSL = document.getElementById('nama_sl');
            const diskonSL = document.getElementById('diskon_sl');
            const jumlahSL = document.getElementById('jumlah_sl');
            const hargaModalSL = document.getElementById('harga_modal_sl');
            const hargaJualSL = document.getElementById('harga_jual_sl');
            const tableParent = document.getElementById('table-detail-sparepart-luar');


            const valNamaSL = namaSL.value;
            const valDiskonSL = diskonSL.value;
            const valJumlahSL = jumlahSL.value;
            const valHargaModalSL = hargaModalSL.value;
            const valHargaJualSL = hargaJualSL.value;
            const subTotalSL = document.createTextNode(numberFormat.format((valHargaJualSL * valJumlahSL) - valDiskonSL));

            // input nama sparepart
            let namaSLInput = document.createElement("input");
            namaSLInput.classList.add("item-diskon");
            namaSLInput.setAttribute("name", "nama_SL[]");
            namaSLInput.setAttribute("type", "text");
            namaSLInput.setAttribute("required", true);
            namaSLInput.setAttribute("value", valNamaSL);

            // diskon Sparepart
            let diskonSLInput = document.createElement("input");
            diskonSLInput.classList.add("item-diskon");
            diskonSLInput.setAttribute("name", "diskon_SL[]");
            diskonSLInput.setAttribute("type", "number");
            diskonSLInput.setAttribute("required", true);
            diskonSLInput.setAttribute("min", 0);
            diskonSLInput.setAttribute("value", valDiskonSL);

            // Jumlah Sparepart
            let jumlahSLInput = document.createElement("input");
            jumlahSLInput.classList.add("item-diskon");
            jumlahSLInput.setAttribute("name", "jumlah_SL[]");
            jumlahSLInput.setAttribute("type", "number");
            jumlahSLInput.setAttribute("required", true);
            jumlahSLInput.setAttribute("min", 0);
            jumlahSLInput.setAttribute("value", valJumlahSL);

            // harga Modal Sparepart
            let hargaModalSLInput = document.createElement("input");
            hargaModalSLInput.classList.add("item-diskon");
            hargaModalSLInput.setAttribute("name", "harga_modal_SL[]");
            hargaModalSLInput.setAttribute("type", "number");
            hargaModalSLInput.setAttribute("required", true);
            hargaModalSLInput.setAttribute("min", 0);
            hargaModalSLInput.setAttribute("value", valHargaModalSL);

            // harga Jual sparepart 
            let hargaJualSLInput = document.createElement("input");
            hargaJualSLInput.classList.add("item-diskon");
            hargaJualSLInput.setAttribute("name", "harga_jual_SL[]");
            hargaJualSLInput.setAttribute("type", "number");
            hargaJualSLInput.setAttribute("required", true);
            hargaJualSLInput.setAttribute("min", 0);
            hargaJualSLInput.setAttribute("value", valHargaJualSL);

            // tombol hapus
            let hapusButtonTextSL = document.createTextNode("X");
            let hapusButtonSL = document.createElement("button");
            hapusButtonSL.classList.add("btn", "btn-danger", "item-delete");
            hapusButtonSL.appendChild(hapusButtonTextSL);
            hapusButtonSL.setAttribute('type', "button");

            // inisiasi kolom
            let row = tableParent.querySelector("tbody").insertRow(-1);
            let namaSLInputCell = row.insertCell(0);
            let diskonSLInputCell = row.insertCell(1);
            let jumlahSLInputCell = row.insertCell(2);
            let hargaModalSLInputCell = row.insertCell(3);
            let hargaJualSLInputCell = row.insertCell(4);
            let subTotalCell = row.insertCell(5);
            subTotalCell.classList.add("subTotal");
            let deleteCell = row.insertCell(6);

            // masukan input ke cell
            namaSLInputCell.appendChild(namaSLInput);
            diskonSLInputCell.appendChild(diskonSLInput);
            jumlahSLInputCell.appendChild(jumlahSLInput);
            hargaModalSLInputCell.appendChild(hargaModalSLInput);
            hargaJualSLInputCell.appendChild(hargaJualSLInput);
            subTotalCell.appendChild(subTotalSL);
            deleteCell.appendChild(hapusButtonSL);

            // delete function
            addEventHapusSL(hapusButtonSL);

            // Reset value
            namaSL.value = '';
            diskonSL.value = '';
            jumlahSL.value = '';
            hargaModalSL.value = '';
            hargaJualSL.value = '';

            countGrandTotal();
            showAlert(valNamaSL);
            return false;
        }

        // delete function
        function addEventHapusSL(element) {
            element.addEventListener("click", function(event) {
                this.parentElement.parentElement.remove();
                countGrandTotal();
            });
        }
        // alert 
        function tambahAlert(item) {

            alert(item + " Ditambahkan");


        }

        document.getElementById("diskon_total").addEventListener('change', function() {
            countGrandTotal();
        });
        document.getElementById("diskon_persen_total").addEventListener('change', function() {
            countGrandTotal();
        });
        document.getElementById("diskon_poin").addEventListener('change', function() {
            countGrandTotal();
        });

        document.getElementById("diskon_total").addEventListener('keyup', function() {
            countGrandTotal();
        });
        document.getElementById("diskon_persen_total").addEventListener('keyup', function() {
            countGrandTotal();
        });
        document.getElementById("diskon_poin").addEventListener('keyup', function() {
            countGrandTotal();
        });
    </script>

Anons79 File Manager Version 1.0, Coded By Anons79
Email: [email protected]