class NHANVIEN(db.Model): # Nhân viên ID_NV = Column(Integer, autoincrement=True, primary_key=True) MANV = Column(CHAR(7), nullable=False, unique=True) TENNV = Column(Text, nullable=False, unique=True) phieunhap = db.relationship('PHIEUNHAP', backref='owner_phieunhap_nhanvien', lazy='dynamic') phieuxuat = db.relationship('PHIEUXUAT', backref='owner_phieuxuat_nhanvien', lazy='dynamic') def __init__(self, MANV, TENNV): self.MANV = MANV self.TENNV = TENNV
class LOAISP(db.Model): # Loại sản phẩm ID_LOAISP = Column(Integer, autoincrement=True, primary_key=True) MALOAI = Column(String(30), nullable=False, unique=True) TENLOAI = Column(Text, nullable=False, unique=True) sanphamnhap = db.relationship('SPN', backref='owner_sanphamnhap_loaisp', lazy='dynamic') sanphamxuat = db.relationship('SPX', backref='owner_sanphamxuat_loaisp', lazy='dynamic') def __init__(self, MALOAI, TENLOAI): self.MALOAI = MALOAI self.TENLOAI = TENLOAI
class PHUONGTIEN(db.Model): # Phương tiện ID_PT = Column(Integer, autoincrement=True, primary_key=True) MAPT = Column(CHAR(7), nullable=False, unique=True) TenPT = Column(Text, nullable=False, unique=True) phieuxuat = db.relationship('PHIEUXUAT', backref='owner_phieuxuat_phuongtien', lazy='dynamic') def __init__(self, MAPT, TenPT): self.MAPT = MAPT self.TenPT = TenPT
class LOAIHINHNHAP(db.Model): # Loại hình nhập ID_LHN = Column(Integer, autoincrement=True, primary_key=True) MALHN = Column(CHAR(7), nullable=False, unique=True) TENLHN = Column(Text, nullable=False, unique=True) phieunhap = db.relationship('PHIEUNHAP', backref='owner_phieunhap_loaihinhnhap', lazy='dynamic') def __init__(self, MALHN, TENLHN): self.MALHN = MALHN self.TENLHN = TENLHN
class SPX(db.Model): # Sản phẩm xuất ID_SPX = Column(Integer, autoincrement=True, primary_key=True) MASPX = Column(String(30), nullable=False, unique=True) TENSPX = Column(Text, nullable=False, unique=True) Id_loaisp = Column(Integer, ForeignKey('LOAISP.ID_LOAISP')) phieuxuat = db.relationship('PHIEUXUAT', backref='owner_phieuxuat_spx', lazy='dynamic') def __init__(self, MASPX, TENSPX, idlsp): self.MASPX = MASPX self.TENSPX = TENSPX self.Id_loaisp = idlsp
class SPN(db.Model): # Sản phẩm nhập ID_SPN = Column(Integer, autoincrement=True, primary_key=True) MASPN = Column(String(30), nullable=False, unique=True) TENSPN = Column(Text, nullable=False, unique=True) Id_loaisp = Column(Integer, ForeignKey('LOAISP.ID_LOAISP')) phieunhap = db.relationship('PHIEUNHAP', backref='owner_phieunhap_spn', lazy='dynamic') def __init__(self, MASPN, TENSPN, idlsp): self.MASPN = MASPN self.TENSPN = TENSPN self.Id_loaisp = idlsp
class HOPDONG(db.Model): # Hợp đồng ID_HD = Column(Integer, autoincrement=True, primary_key=True) MAHD = Column(CHAR(7), nullable=False, unique=True) TENHD = Column(Text, nullable=False, unique=True) Id_ncc = Column(Integer, ForeignKey('NCC.ID_NCC')) phieunhap = db.relationship('PHIEUNHAP', backref='owner_phieunhap_hopdong', lazy='dynamic') def __init__(self, MAHD, TENHD, idncc): self.MAHD = MAHD self.TENHD = TENHD self.Id_ncc = idncc
class NCC(db.Model): # Nhà cung cấp ID_NCC = db.Column(db.Integer, autoincrement=True, primary_key=True) MANCC = db.Column(db.CHAR(7), nullable=False, unique=True) TENNCC = db.Column(db.Text, nullable=False, unique=True) DIACHI = db.Column(db.Text) NGUOILH = db.Column(db.Text) # Người liên hệ SDT = db.Column(db.String(11)) Hopdong = db.relationship('HOPDONG', backref='owner_hopdong_ncc', lazy='dynamic') def __init__(self, MANCC, TENNCC, DIACHI, NGUOILH, SDT): self.MANCC = MANCC self.TENNCC = TENNCC self.DIACHI = DIACHI self.NGUOILH = NGUOILH self.SDT = SDT
class KHACHHANG(db.Model): # Khách hàng ID_KH = Column(Integer, autoincrement=True, primary_key=True) MA_KH = Column(CHAR(7), nullable=False, unique=True) TENKH = Column(Text, nullable=False, unique=True) DIACHI = Column(Text) SDT = Column(String(11)) NGUOILH = Column(Text) # Người liên hệ phieuxuat = db.relationship('PHIEUXUAT', backref='owner_phieuxuat_khachhang', lazy='dynamic') def __init__(self, MA_KH, TENKH, DIACHI, SDT, NGUOILH): self.MA_KH = MA_KH self.TENKH = TENKH self.DIACHI = DIACHI self.SDT = SDT self.NGUOILH = NGUOILH
class PHIEUXUAT(db.Model): # Phiếu xuất ID_PX = Column(db.Integer, autoincrement=True, primary_key=True) MAPX = Column(CHAR(7), nullable=False, unique=True) NGAYDATHANG = Column(DATE) NGAYGIAO = Column(DATE) PHAN_TRAM_DU_THIEU = Column(Text) TRANGTHAI = Column(Text) # Thùng hoặc KG POST_OF_DISCHARGE = Column(Text) SLXUAT = Column(Text) SLXTHUC = Column(Text) DVT = Column(String(20)) PRICE = Column(DECIMAL) TONGTIEN = Column(DECIMAL) Id_nv = Column(Integer, ForeignKey('NHANVIEN.ID_NV')) Id_kh = Column(Integer, ForeignKey('KHACHHANG.ID_KH')) Id_pt = Column(Integer, ForeignKey('PHUONGTIEN.ID_PT')) Id_spx = Column(Integer, ForeignKey('SPX.ID_SPX')) kho = db.relationship('KHO', backref='owner_kho_phieuxuat', lazy='dynamic') def __init__(self, MAPX, NGAYDATHANG, NGAYGIAO, PHANTRAMDUTHIEU, TRANGTHAI, POST_OF_DISCHARGE, SLXUAT, SLXTHUC, DVT, PRICE, TONGTIEN, idnv, idkh, idpt, idspx): self.MAPX = MAPX self.NGAYDATHANG = NGAYDATHANG self.NGAYGIAO = NGAYGIAO self.PHAN_TRAM_DU_THIEU = PHANTRAMDUTHIEU self.TRANGTHAI = TRANGTHAI self.POST_OF_DISCHARGE = POST_OF_DISCHARGE self.SLXUAT = SLXUAT self.SLXTHUC = SLXTHUC self.DVT = DVT self.PRICE = PRICE self.TONGTIEN = TONGTIEN self.Id_nv = idnv self.Id_kh = idkh self.Id_pt = idpt self.Id_spx = idspx