示例#1
0
 def deleteKaryawan(self):
     self.showKaryawan()
     while True:
         try:
             jawabDelete = int(input("\nMasukkan id yang mau di hapus : "))
             tempAnswer = []
             query = (
                 'SELECT ID_Person FROM person WHERE Role = "Karyawan"')
             for x in self.fetchalll(query):
                 tempAnswer.append(x[0])
             if jawabDelete in tempAnswer:
                 tempID = []
                 query = (
                     'SELECT ID_Person FROM person WHERE Role = "Karyawan"')
                 for x in self.fetchalll(query):
                     tempID.append(x[0])
                 if jawabDelete in tempID:
                     sql = "DELETE FROM person WHERE ID_Person = {}".format(
                         jawabDelete)
                     self.fetchone(sql)
                     View.done()
                     break
             else:
                 View.inputError()
         except KeyboardInterrupt:
             View.interrupt()
             break
         except:
             View.inputError()
示例#2
0
    def ambilBarang(self):
        self.showBarang()
        while True:
            try:
                jawabID = int(input("\nMasukkan id yang mau di ambil : "))
                tempID = []
                query = ('SELECT ID_Barang FROM barang')
                for x in self.fetchalll(query):
                    tempID.append(x[0])
                if jawabID in tempID:
                    jawabStok = int(
                        input("Masukkan stock yang mau di ambil : "))
                    if jawabStok <= 0:
                        View.inputZero()
                    else:
                        sql = """
                        Select Jumlah_Barang
                        FROM barang
                        WHERE ID_Barang = {}
                        """.format(jawabID)
                        res = self.fetchone(sql)
                        for x in res:
                            if jawabStok > x:
                                print("Barang yang diambil melebihi stok")
                                break
                            else:
                                hasilStok = x - jawabStok
                                sql = """
                                UPDATE barang
                                SET Jumlah_Barang = {}
                                WHERE ID_Barang = {}
                                """.format(hasilStok, jawabID)
                                self.fetchone(sql)

                                sql = """SELECT Satuan FROM barang
                                WHERE ID_Barang = {}""".format(jawabID)
                                res = self.fetchone(sql)
                                for y in res:
                                    satuan = y

                                sql = """INSERT INTO history (PersonID,
                                BarangID, Keterangan, Jumlah, Satuan, Tanggal)
                                VALUES (%s, %s, %s, %s, %s, %s)"""
                                val = (self.UserID, jawabID, "Output",
                                       jawabStok, satuan, datetime.now())
                                self.inputDB(sql, val)
                                View.done()
                        break
                else:
                    Views.jawabFalse()
            except KeyboardInterrupt:
                View.interrupt()
                break
            except:
                View.inputError()
示例#3
0
    def tambahBarang(self):
        while True:
            try:
                self.nama = input("Masukkan nama barang : ").title()
                tempNama = []
                query = ('SELECT Nama_Barang FROM barang')
                for x in self.fetchalll(query):
                    tempNama.append(x[0])
                if self.nama in tempNama:
                    print("Nama barang sudah ada!!")
                elif len(self.nama) == 0:
                    View.inputError()
                else:
                    self.stok = int(input("Masukkan jumlah barang : "))
                    self.satuan = input("Masukkan nama satuannya : ").lower()
                    if len(self.satuan) == 0:
                        View.inputError()
                    else:
                        self.tahun = int(
                            input(
                                "Masukkan tahun kadaluarsa barang (YYYY) : "))
                        if len(str(self.tahun)) != 4:
                            View.inputError()
                        else:
                            self.bulan = int(
                                input(
                                    "Masukkan bulan kadaluarsa barang (MM) : ")
                            )
                            if len(str(self.bulan)) != 2:
                                View.inputError()
                            else:
                                self.hari = int(
                                    input(
                                        "Masukkan hari kadaluarsa barang (DD) : "
                                    ))
                                if len(str(self.hari)) != 2:
                                    View.inputError()
                                else:
                                    self.tanggal = "{}-{}-{}".format(
                                        self.tahun, self.bulan, self.hari)

                                    sql = """INSERT INTO barang (Nama_Barang , Jumlah_Barang , Satuan, Tanggal_Kadaluarsa)
                                    VALUES (%s, %s, %s, %s)"""
                                    val = (self.nama, self.stok, self.satuan,
                                           self.tanggal)
                                    self.inputDB(sql, val)

                                    sql = """SELECT ID_Barang FROM barang
                                    WHERE Nama_Barang = '{}'""".format(
                                        self.nama)
                                    res = self.fetchone(sql)
                                    for x in res:
                                        self.barangID = x

                                    sql = """INSERT INTO history (PersonID,
                                    BarangID, Keterangan, Jumlah, Satuan, Tanggal)
                                    VALUES (%s, %s, %s, %s, %s, %s)"""
                                    val = (self.UserID, self.barangID, "Input",
                                           self.stok, self.satuan,
                                           datetime.now())
                                    self.inputDB(sql, val)
                                    View.done()
                                    break
            except KeyboardInterrupt:
                View.interrupt()
                break
            except:
                View.inputError()