class Siswa(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) nis_siswa = db_sql.Column(db_sql.String(32), nullable=False, unique=True) nama_siswa = db_sql.Column(db_sql.String(32), nullable=False) jenis_kelamin = db_sql.Column(db_sql.Integer(), nullable=False) # 0: laki-laki, 1: perempuan alamat_siswa = db_sql.Column(db_sql.String(128), nullable=False) agama = db_sql.Column(db_sql.String(32), nullable=False) jenis_siswa = db_sql.Column(db_sql.Integer(), nullable=False) # 0: reguler, 1: beasiswa id_tahun_ajaran = db_sql.Column(db_sql.Integer(), db_sql.ForeignKey('tahun_ajaran.id'), nullable=False) id_kelas = db_sql.Column(db_sql.Integer(), db_sql.ForeignKey('kelas.id'), nullable=False) # id_tahun_ajaran = db_sql.Column(db_sql.Integer(), nullable=False) # id_kelas = db_sql.Column(db_sql.Integer(), nullable=False) def to_dict(self): return { 'id': self.id, 'nis': self.nis_siswa, 'nama': self.nama_siswa, 'jenis_kelamin': self.jenis_kelamin, 'alamat': self.alamat_siswa, 'agama': self.agama, 'id_tahun_ajaran': self.id_tahun_ajaran, 'id_kelas': self.id_kelas, 'jenis_siswa': self.jenis_siswa } def to_table(self, index, kelas, tahun_ajaran): return { 'id': self.id, 'index': index + 1, 'nis': self.nis_siswa, 'nama': self.nama_siswa, 'jenis_kelamin': self.jenis_kelamin, 'alamat': self.alamat_siswa, 'agama': self.agama, 'id_tahun_ajaran': self.id_tahun_ajaran, 'id_kelas': self.id_kelas, 'tahun_ajaran': tahun_ajaran, 'kelas': kelas, 'jenis_siswa': self.jenis_siswa }
class Pembayaran(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) uuid = db_sql.Column(db_sql.String(), nullable=False, unique=True) tahun = db_sql.Column(db_sql.Integer(), nullable=False) bulan = db_sql.Column(db_sql.Integer(), nullable=False) nis_siswa = db_sql.Column(db_sql.String(32), nullable=False) nama_siswa = db_sql.Column(db_sql.String(32), nullable=False) jenis_siswa = db_sql.Column(db_sql.Integer(), nullable=False) tgl_pembayaran = db_sql.Column(db_sql.Date(), nullable=False, default=datetime.datetime.utcnow()) nominal = db_sql.Column(db_sql.Integer(), nullable=False) status = db_sql.Column(db_sql.Boolean(), nullable=False) # false: tepat, true: tunggakan def to_table(self, index): return { 'id': self.id, 'index': index + 1, 'uuid': self.uuid, 'tahun': self.tahun, 'bulan': self.bulan, 'nis_siswa': self.nis_siswa, 'nama_siswa': self.nama_siswa, 'jenis_siswa': self.jenis_siswa, 'tgl_pembayaran': str(self.tgl_pembayaran), 'nominal': self.nominal, 'status': self.status } def to_dict(self, kelas): return { 'id': self.id, 'uuid': self.uuid, 'tahun': self.tahun, 'bulan': self.bulan, 'nis_siswa': self.nis_siswa, 'nama_siswa': self.nama_siswa, 'jenis_siswa': self.jenis_siswa, 'tgl_pembayaran': str(self.tgl_pembayaran), 'nominal': self.nominal, 'status': self.status, 'kelas': kelas }
class User(db_sql.Model, UserMixin): id = db_sql.Column(db_sql.Integer(), primary_key=True) username = db_sql.Column(db_sql.String(32), nullable=False, unique=True) password = db_sql.Column(db_sql.String(95), nullable=False) nama = db_sql.Column(db_sql.String(32), nullable=False) def check_password(self, password): return check_password_hash(self.password, password) def to_dict(self): return {'id': self.id, 'username': self.username, 'nama': self.nama}
class Sekolah(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) nama_sekolah = db_sql.Column(db_sql.String(32), nullable=False) alamat_sekolah = db_sql.Column(db_sql.String(32), nullable=False) kepala_sekolah = db_sql.Column(db_sql.String(32), nullable=False) def to_dict(self): return { 'id': self.id, 'nama_sekolah': self.nama_sekolah, 'alamat_sekolah': self.alamat_sekolah, 'kepala_sekolah': self.kepala_sekolah }
class TahunAjaran(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) tahun_ajaran = db_sql.Column(db_sql.String(32), nullable=False, unique=True) siswas = db_sql.relationship('Siswa', backref='tahun_ajaran', lazy=True) def to_table(self, idx): return { 'id': self.id, 'index': idx + 1, 'tahun_ajaran': self.tahun_ajaran, 'siswa': len(self.siswas) } def to_dict(self): return {'id': self.id, 'tahun_ajaran': self.tahun_ajaran}
class Kelas(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) kelas = db_sql.Column(db_sql.String(32), nullable=False, unique=True) siswas = db_sql.relationship('Siswa', backref='kelas', lazy=True) def to_dict(self, index): female = Siswa.query.filter((Siswa.id_kelas == self.id) & (Siswa.jenis_kelamin == 1)).count() male = Siswa.query.filter((Siswa.id_kelas == self.id) & (Siswa.jenis_kelamin == 0)).count() return { 'id': self.id, 'index': index + 1, 'kelas': self.kelas, 'laki': male, 'perempuan': female }
class User(db_sql.Model, UserMixin): id = db_sql.Column(db_sql.Integer(), primary_key=True) fullname = db_sql.Column(db_sql.String(32)) username = db_sql.Column(db_sql.String(32), nullable=False, unique=True) password = db_sql.Column(db_sql.String(95), nullable=False) instance = db_sql.Column(db_sql.String(32), nullable=False) location = db_sql.Column(db_sql.Text(), nullable=False) created = db_sql.Column(db_sql.DateTime()) updated = db_sql.Column(db_sql.DateTime()) def add_timestamp(self): self.created = datetime_jakarta() self.updated = self.created def update_timestamp(self): self.updated = datetime_jakarta() @staticmethod def add(data): try: data.add_timestamp() data.password = User.hash_password(data.password) db_sql.session.add(data) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def update(data): try: data.update_timestamp() data.password = User.hash_password(data.password) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def delete(id_data): try: data = User.query.get(id_data) db_sql.session.delete(data) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def check_username(username): data = User.query.filter(User.username == username).first() if data is not None: return True return False @staticmethod def hash_password(password): hash_password = generate_password_hash(password) return hash_password def check_password(self, password): return check_password_hash(self.password, password) def to_dict(self): data = { 'id': self.id, 'username': self.username, 'instance': self.instance, 'location': self.location } return data
class User(db_sql.Model, UserMixin): id = db_sql.Column(db_sql.Integer(), primary_key=True) fullname = db_sql.Column(db_sql.String(32), nullable=False) username = db_sql.Column(db_sql.String(32), nullable=False, unique=True) password = db_sql.Column(db_sql.String(95), nullable=False) created = db_sql.Column(db_sql.DateTime()) updated = db_sql.Column(db_sql.DateTime()) def add_timestamp(self): self.created = datetime_jakarta() self.updated = self.created def update_timestamp(self): self.updated = datetime_jakarta() @staticmethod def add(data): try: data.add_timestamp() # data.password = User.hash_password(data.password) db_sql.session.add(data) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def update(data): try: data.update_timestamp() # data.password = User.hash_password(data.password) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def delete(id_data): try: data = User.query.get(id_data) db_sql.session.delete(data) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False def to_dict(self): return { 'id': self.id, 'username': self.username, 'fullname': self.fullname }
class Computer( db_sql.Model, ): id = db_sql.Column(db_sql.Integer(), primary_key=True) computer_id = db_sql.Column(db_sql.String(40), nullable=False, unique=True) computer_name = db_sql.Column(db_sql.String(32), nullable=False) computer_location = db_sql.Column(db_sql.String(32), nullable=False) computer_power_status = db_sql.Column(db_sql.Integer(), default=0, nullable=False) # 0: off, 1: on computer_cmd = db_sql.Column(db_sql.Integer(), default=1, nullable=False) # 0: off, 1: on, 2: restart computer_cmd_date = db_sql.Column(db_sql.Integer(), default=timestamp_jakarta(), nullable=False) computer_ping_timestamp = db_sql.Column(db_sql.Integer(), default=timestamp_jakarta(), nullable=False) computer_instance = db_sql.Column(db_sql.String(32), nullable=False) created = db_sql.Column(db_sql.DateTime()) updated = db_sql.Column(db_sql.DateTime()) def add_timestamp(self): self.created = datetime_jakarta() self.updated = self.created def update_timestamp(self): self.updated = datetime_jakarta() @staticmethod def add(data): try: data.add_timestamp() db_sql.session.add(data) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def update(data): try: data.update_timestamp() db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def delete(id_data): try: data = Computer.query.get(id_data) db_sql.session.delete(data) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False def to_dict(self): data = { 'id': self.computer_id, 'name': self.computer_name, 'location': self.computer_location, 'power_status': self.computer_power_status, 'instance': self.computer_instance, 'cmd': self.computer_cmd, 'cmd_date': self.computer_cmd_date } return data def on_ping(self): try: self.computer_ping_timestamp = timestamp_jakarta() self.computer_power_status = 1 db_sql.session.commit() except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() def on_action(self): self.computer_cmd_date = timestamp_jakarta()
class Category(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) category_code = db_sql.Column(db_sql.String(10), nullable=False, unique=True) category_name = db_sql.Column(db_sql.String(32), nullable=False) created = db_sql.Column(db_sql.DateTime()) updated = db_sql.Column(db_sql.DateTime()) def add_timestamp(self): self.created = datetime_jakarta() self.updated = self.created def update_timestamp(self): self.updated = datetime_jakarta() @staticmethod def add(item): try: item.add_timestamp() db_sql.session.add(item) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def update(item): try: item.update_timestamp() db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def delete(category_code): try: item = Category.query.filter( Category.category_code == category_code).first() db_sql.session.delete(item) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False def to_dict(self): data = { 'id': self.id, 'category_code': self.category_code, 'category_name': self.category_name } return data def to_table(self, index, product_total): data = { 'number': index + 1, 'category_code': self.category_code, 'category_name': self.category_name, 'product_total': product_total } return data def to_list(self): data = [self.category_code, self.category_name] return data
class Transaction(db_sql.Model): id = db_sql.Column(db_sql.Integer(), primary_key=True) transaction_code = db_sql.Column(db_sql.String(36), nullable=False) product_code = db_sql.Column(db_sql.String(10), nullable=False) product_price = db_sql.Column(db_sql.Integer(), nullable=False, default=0) product_stock_price = db_sql.Column(db_sql.Integer(), nullable=False, default=0) transaction_type = db_sql.Column(db_sql.Integer(), nullable=False) transaction_count = db_sql.Column(db_sql.Integer(), nullable=False) transaction_date = db_sql.Column(db_sql.Date(), nullable=False) created = db_sql.Column(db_sql.DateTime()) updated = db_sql.Column(db_sql.DateTime()) def add_timestamp(self): self.created = datetime_jakarta() self.updated = self.created def update_timestamp(self): self.updated = datetime_jakarta() @staticmethod def add(item): try: item.transaction_code = str(uuid4()) item.transaction_date = date_jakarta_o() item.add_timestamp() db_sql.session.add(item) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def update(item): try: item.update_timestamp() db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False @staticmethod def delete(transaction_code): try: item = Transaction.query.filter( Transaction.product_code == transaction_code).first() db_sql.session.delete(item) db_sql.session.commit() return True except Exception as e: print(e) db_sql.session.rollback() db_sql.session.flush() return False def to_dict(self): data = { 'id': self.id, 'transaction_code': self.transaction_code, 'product_code': self.product_code, 'transaction_type': self.transaction_type, 'transaction_count': self.transaction_count, 'transaction_date': str(self.transaction_date), 'stock_price': self.product_stock_price, 'product_price': self.product_price } return data def to_table(self, index, product_name): data = { 'number': index + 1, 'transaction_code': self.transaction_code, 'product_code': self.product_code, 'product_name': product_name, 'product_price': self.product_price, 'product_stock_price': self.product_stock_price, 'transaction_type': self.transaction_type, 'transaction_count': self.transaction_count, 'transaction_date': str(self.transaction_date), } return data