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()
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()
def createKaryawan(self): while True: try: self.nama = input("Masukkan Nama Karyawan : ").title() query = ('SELECT Nama, username role FROM person') tempNama = [] tempUsername = [] for x in self.fetchalll(query): tempNama.append(x[0]) tempUsername.append(x[1]) if len(self.nama) == 0: View.inputError() else: self.umur = int(input("Masukkan umur Karyawan : ")) self.jenisKelamin = input( "Masukkan jenis kelamin Karyawan (L/P) : ").upper() if len(self.jenisKelamin) == 0: View.inputError() elif self.jenisKelamin != 'L' or self.jenisKelamin != 'P': self.role = "Karyawan" self.username = input( "Masukkan username Karyawan : ").lower() for i in range(len(tempNama)): if self.username == tempUsername[i]: print("username sudah ada!") elif len(self.username) == 0: View.inputError() else: self.password = input( "Masukkan password Karyawan : ") if len(self.password) == 0: View.inputError() else: self.created = datetime.now() sql = """INSERT INTO person (Nama , Umur , Jenis_Kelamin, Role , username , password , created) VALUES (%s, %s, %s, %s, %s, %s, %s)""" val = (self.nama, self.umur, self.jenisKelamin, self.role, self.username, self.password, self.created) self.inputDB(sql, val) break else: print("Silahkan Masukkan L / P") except ValueError: View.inputError() except KeyboardInterrupt: View.interrupt() break
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()