Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var namapro = document.getElementById("namaProduk").value
- if (namapro == "") {
- document.getElementById("button9").style.display = "inline"
- document.getElementById("button6").style.display = "none"
- document.getElementById("button").style.display = "none"
- }
- kodeproduk = []
- nama = []
- harga = []
- satuan = []
- gambar = []
- kategori = []
- stok = []
- tampil = document.getElementById('tampildata')
- function showData() {
- tampil.innerHTML = ""
- for (i = 0; i < nama.length; i++) {
- nodata = i + 1
- tampil.innerHTML += "<tr>" +
- "<th>" + nodata + "</th>" +
- "<td>" + kodeproduk[i] + "</td>" +
- "<td>" + nama[i] + "</td>" +
- "<td>" + kategori[i] + "</td>" +
- "<td id='stock"+ nodata +"'>" + stok[i] + "</td>" +
- "<td><img src=" + gambar[i] + " id='image' width='100' height=110'></td>" +
- "<td>" +
- "<button class='btn btn-warning mr-2' onclick='editdata(" +
- i +
- ")'>Edit</button>" +
- "<button class='btn-danger btn' onclick='hapusdata(" + i +
- ")'>Hapus</button>";
- var stocks = document.getElementById('stock' + nodata + '')
- if (Number(stocks.innerHTML) < 5) {
- stocks.style.backgroundColor = "red"
- stocks.style.color = "white"
- } else {
- stocks.style.backgroundColor = ""
- stocks.style.color = ""
- }
- }
- }
- function batal() {
- document.getElementById('kodeProduk').value = ""
- document.getElementById('namaProduk').value = ""
- document.getElementById('hargaProduk').value = ""
- document.getElementById('satuan').value = ""
- document.getElementById('kategori').value = ""
- document.getElementById('stokAwal').value = ""
- document.getElementById('urlGambar').value = ""
- document.getElementById("button9").style.display = "inline"
- document.getElementById("button5").style.display = "none"
- document.getElementById("button").style.display = "none"
- }
- function add() {
- var newkode = document.getElementById('kodeProduk').value
- var newnama = document.getElementById('namaProduk').value
- var newharga = document.getElementById('hargaProduk').value
- var newsatuan = document.getElementById('satuan').value
- var newkategori = document.getElementById('kategori').value
- var newstok = document.getElementById('stokAwal').value
- var newgambar = document.getElementById('urlGambar').value
- if (newnama == '') {
- alert('silahkan masukkan data terlebih dahulu!')
- } else {
- kodeproduk.push(newkode)
- nama.push(newnama)
- harga.push(newharga)
- satuan.push(newsatuan)
- gambar.push(newgambar)
- kategori.push(newkategori)
- stok.push(newstok)
- showData()
- document.getElementById('kodeProduk').value = ""
- document.getElementById('namaProduk').value = ""
- document.getElementById('hargaProduk').value = ""
- document.getElementById('satuan').value = ""
- document.getElementById('kategori').value = ""
- document.getElementById('stokAwal').value = ""
- document.getElementById('urlGambar').value = ""
- }
- }
- var index = []
- function editdata(i) {
- document.getElementById('kodeProduk').value = kodeproduk[i]
- document.getElementById('namaProduk').value = nama[i]
- document.getElementById('urlGambar').value = gambar[i]
- document.getElementById('satuan').value = satuan[i]
- document.getElementById('hargaProduk').value = harga[i]
- document.getElementById('kategori').value = kategori[i]
- document.getElementById('stokAwal').value = stok[i]
- document.getElementById("button9").style.display = "none"
- document.getElementById("button6").style.display = "inline"
- document.getElementById("button").style.display = "inline"
- index.push(i)
- }
- function editSimpan() {
- var newkode = document.getElementById('kodeProduk').value
- var newnama = document.getElementById('namaProduk').value
- var newharga = document.getElementById('hargaProduk').value
- var newsatuan = document.getElementById('satuan').value
- var newkategori = document.getElementById('kategori').value
- var newstok = document.getElementById('stokAwal').value
- var newgambar = document.getElementById('urlGambar').value
- if (newnama == '') {
- alert('silahkan masukkan data terlebih dahulu!')
- } else {
- kodeproduk[index] = newkode
- nama[index] = newnama
- harga[index] = newharga
- satuan[index] = newsatuan
- gambar[index] = newgambar
- kategori[index] = newkategori
- stok[index] = newstok
- showData()
- index.pop()
- document.getElementById('kodeProduk').value = ""
- document.getElementById('namaProduk').value = ""
- document.getElementById('hargaProduk').value = ""
- document.getElementById('satuan').value = ""
- document.getElementById('kategori').value = ""
- document.getElementById('stokAwal').value = ""
- document.getElementById('urlGambar').value = ""
- document.getElementById("button9").style.display = "inline"
- document.getElementById("button6").style.display = "none"
- document.getElementById("button").style.display = "none"
- }
- }
- function hapusdata(i) {
- if (confirm('apakah kamu yakin ingin menghapus data?')) {
- nama.splice(i, 1);
- kodeproduk.splice(i, 1);
- kategori.splice(i, 1);
- stok.splice(i, 1);
- gambar.splice(i, 1);
- showData()
- }
- }
- function kodep(value) {
- var idkode = []
- var kodekatagori = value.split(" ").filter(function (e) {
- return e.trim().length > 0;
- });
- for (i = 0; i < kodekatagori.length; i++) {
- if (kodekatagori.length == 1) {
- var code = kodekatagori[i].slice(0, 2)
- } else {
- var code = kodekatagori[i].slice(0, 1)
- }
- idkode.push(code)
- }
- var kodepr = idkode.join("")
- kodepr = kodepr.toUpperCase()
- if (idkode.length == 0) {
- document.getElementById("kodeProduk").value = ''
- } else {
- var count = 1;
- for (i = 0; i < kategori.length; ++i) {
- if (kategori[i].toLowerCase() == value.toLowerCase()) {
- count++;
- }
- }
- if (count < 10) {
- document.getElementById("kodeProduk").value = kodepr + '-00' + count
- } else if (count < 100) {
- document.getElementById("kodeProduk").value = kodepr + '-0' + count
- } else {
- document.getElementById("kodeProduk").value = kodepr + '-' + count
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement