class Receipt(db.Model): __tablename__ = 'receipts' id = db.Column(db.Integer, primary_key=True) receipt_number = db.Column(db.String(), nullable=False) date_created = db.Column(db.Date, default=datetime.now) received_from = db.Column(db.String(120), nullable=False) sum_in_words = db.Column(db.String(120), nullable=False) reason = db.Column(db.String(255), nullable=False) cash_cheque = db.Column(db.String(), nullable=False) balance = db.Column(db.String(20), nullable=False) amount = db.Column(db.String, nullable=False) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) def get_last_id(): qry = Receipt.query.order_by(Invoice.id.desc()).first() x = qry.id ym = date.today().strftime("%y%m") q_custom_id = "" + ym + str(x).zfill(3) + "" return q_custom_id def __init__(self, receipt_number, date_created, received_from, sum_in_words, reason, cash_cheque, balance, amount, user_id): self.receipt_number = receipt_number self.date_created = date_created self.received_from = received_from self.sum_in_words = sum_in_words self.reason = reason self.cash_cheque = cash_cheque self.balance = balance self.amount = amount self.user_id = user_id
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(120), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) designation = db.Column(db.String(120), nullable=False) image_file = db.Column(db.String(120), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) is_admin = db.Column(db.Boolean, default=True) invoice = db.relationship('Invoice', backref='author', lazy=True) receipt = db.relationship('Receipt', backref='receiptAuthor', lazy=True) def check_password(self, password): """Check hashed password.""" return check_password_hash(self.password, password) def get_reset_token(self, expires_sec=1800): s = Serializer(current_app.config['SECRET_KEY'], expires_sec) return s.dumps({'user_id': self.id}).decode('utf-8') @staticmethod def verify_reset_token(token): s = Serializer(current_app.config['SECRET_KEY']) try: user_id = s.loads(token)['user_id'] except: return None return User.query.get(user_id) def __repr__(self): return f" User('{self.username}','{self.email}','{self.designation}','{self.image_file}')"
class User(db.Model, UserMixin): __tablename__ = 'users' id = db.Column(db.Integer, primary_key=True) username = db.Column(db.String(120), unique=True, nullable=False) email = db.Column(db.String(120), unique=True, nullable=False) designation = db.Column(db.String(120), nullable=False) image_file = db.Column(db.String(120), nullable=False, default='default.jpg') password = db.Column(db.String(60), nullable=False) is_admin = db.Column(db.Boolean, default=True) invoice = db.relationship('Invoice', backref='author', lazy=True) def __repr__(self): return f" User('{self.username}','{self.email}','{self.designation}','{self.image_file}')"
class InvoiceLineItem(db.Model): __tablename__ = 'line_items' id = db.Column(db.Integer, primary_key=True) prof_heading = db.Column(db.String(500), nullable=True) prof_sub1 = db.Column(db.String(500), nullable=True) prof_sub2 = db.Column(db.String(500), nullable=True) prof_sub3 = db.Column(db.String(500), nullable=True) prof_sub4 = db.Column(db.String(500), nullable=True) prof_sub5 = db.Column(db.String(500), nullable=True) invoice_id = db.Column(db.Integer, db.ForeignKey('invoice.id', ondelete='SET NULL'), nullable=False) # Relationship invoice = db.relationship('Invoice', backref=db.backref('laps', lazy='dynamic', passive_deletes=True, collection_class=list))
class InvoiceLineItem(db.Model): __tablename__ = 'line_items' id = db.Column(db.Integer, primary_key=True) notes = db.Column(db.String(255), nullable=False) disbursements = db.Column(db.String, nullable=True) professional_fees = db.Column(db.String, nullable=True) amount = db.Column(db.Float, nullable=False) invoice_id = db.Column(db.Integer, db.ForeignKey('invoice.id'), nullable=False) # Relationship invoice = db.relationship('Invoice', backref=db.backref('laps', lazy='dynamic', collection_class=list))
class disbursements(db.Model): __tablename__ = 'disbursementsfees' id = db.Column(db.Integer, primary_key=True) disbursement_amount = db.Column(db.Float, default='0.0') disb_heading = db.Column(db.String, nullable=True) disb_sub1 = db.Column(db.String(500), nullable=True) disb_sub2 = db.Column(db.String(500), nullable=True) disb_sub3 = db.Column(db.String(500), nullable=True) invoice_id = db.Column(db.Integer, db.ForeignKey('invoice.id', ondelete='SET NULL'), nullable=False) # Relationship invoice = db.relationship('Invoice', backref=db.backref('laps2', lazy='dynamic', passive_deletes=True, collection_class=list))
class Invoice(db.Model): __tablename__ = 'invoice' id = db.Column(db.Integer, primary_key=True) #ref_number = db.Column(db.Integer,unique=True, nullable=False) ref_number = db.Column(db.String(), nullable=False) name_to = db.Column(db.String(200), nullable=False) address_to = db.Column(db.String, nullable=False) telephone_to = db.Column(db.String, nullable=True) email_to = db.Column(db.String, nullable=True) box_number_to = db.Column(db.String, nullable=True) terms = db.Column(db.String, nullable=False) issue_date = db.Column(db.Date, nullable=False) due_date = db.Column(db.Date, nullable=False) vat = db.Column(db.String, nullable=True) user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False) def get_last_id(): qry = Invoice.query.order_by(Invoice.id.desc()).first() x = qry.id ym = date.today().strftime("%y%m") q_custom_id = "" + ym + str(x).zfill(3) + "" return q_custom_id def __init__(self, ref_number, name_to, address_to, telephone_to, email_to, box_number_to, vat, terms, issue_date, due_date, user_id): self.ref_number = ref_number self.name_to = name_to self.address_to = address_to self.telephone_to = telephone_to self.email_to = email_to self.box_number_to = box_number_to self.vat = vat self.terms = terms self.issue_date = issue_date self.due_date = due_date self.user_id = user_id
class Invoice(db.Model): __tablename__ = 'invoice' __searchable__ = ['ref_number', 'name_to', 'company_name'] id = db.Column(db.Integer, primary_key=True) #ref_number = db.Column(db.Integer,unique=True, nullable=False) ref_number = db.Column(db.String(), nullable=False) name_to = db.Column(db.String(200), nullable=False) company_name = db.Column(db.String(200), nullable=True) address_to = db.Column(db.String, nullable=False) telephone_to = db.Column(db.String, nullable=True) email_to = db.Column(db.String, nullable=True) box_number_to = db.Column(db.String, nullable=True) terms = db.Column(db.String, nullable=False) issue_date = db.Column(db.Date, nullable=False) due_date = db.Column(db.Date, nullable=False) vat = db.Column(db.String, nullable=True) bank = db.Column(db.String, nullable=True) bank_branch = db.Column(db.String, nullable=True) swift_code = db.Column(db.String, nullable=True) account_number = db.Column(db.String, nullable=True) professional_amount = db.Column(db.Float, default='0.0') user_id = db.Column(db.Integer, db.ForeignKey('users.id', ondelete='SET NULL'), nullable=False) def get_last_id(): qry = Invoice.query.order_by(Invoice.id.desc()).first() x = qry.id ym = date.today().strftime("%y%m") q_custom_id = "" + ym + str(x).zfill(3) + "" return q_custom_id def __init__(self, ref_number, name_to, address_to, telephone_to, company_name, email_to, box_number_to, vat, terms, issue_date, due_date, bank, bank_branch, swift_code, account_number, professional_amount, user_id): self.ref_number = ref_number self.name_to = name_to self.address_to = address_to self.telephone_to = telephone_to self.company_name = company_name self.email_to = email_to self.box_number_to = box_number_to self.vat = vat self.terms = terms self.issue_date = issue_date self.due_date = due_date self.bank self.bank_branch self.swift_code self.account_number self.professional_amount = professional_amount self.user_id = user_id