diff --git a/accounts/views.py b/accounts/views.py index d808ffe..37a20f4 100644 --- a/accounts/views.py +++ b/accounts/views.py @@ -15,7 +15,7 @@ def login(): form = LoginForm(request.form) if request.method == 'POST': if form.validate_on_submit(): - user = User.query.filter_by(name=request.form['username']).first() + user = User.query.filter_by(name=request.form['username'].strip()).first() if user is not None and bcrypt.check_password_hash( user.password, request.form['password'] ): diff --git a/coinage.py b/coinage.py index fbd3667..d986cf4 100644 --- a/coinage.py +++ b/coinage.py @@ -4,11 +4,12 @@ from flask_bcrypt import Bcrypt from flask_login import LoginManager + app = Flask(__name__) bcrypt = Bcrypt(app) login_manager = LoginManager() login_manager.init_app(app) -app.config.from_object('config.ProductionConfig') +app.config.from_object('config.DevelopmentConfig') app.config['SQLALCHEMY_POOL_RECYCLE'] = 299 app.config['SQLALCHEMY_POOL_TIMEOUT'] = 20 db = SQLAlchemy(app) @@ -17,8 +18,8 @@ from contributions.views import contributions_blueprint from summary.views import summary_blueprint from loans.views import loans_blueprint -from interestearned.views import interestearned_blueprint from customers.views import customers_blueprint +from interestearned.views import interestearned_blueprint from notes.views import notes_blueprint from guidelines.views import guidelines_blueprint from accounts.views import accounts_blueprint @@ -29,8 +30,8 @@ app.register_blueprint(home_blueprint) app.register_blueprint(summary_blueprint) app.register_blueprint(loans_blueprint) -app.register_blueprint(interestearned_blueprint) app.register_blueprint(customers_blueprint) +app.register_blueprint(interestearned_blueprint) app.register_blueprint(notes_blueprint) app.register_blueprint(accounts_blueprint) app.register_blueprint(users_blueprint) diff --git a/config.py b/config.py index fdd0a21..cd13e2f 100644 --- a/config.py +++ b/config.py @@ -3,7 +3,7 @@ # default configuration class BaseConfig(object): - DEBUG = False + #DEBUG = False SECRET_KEY = 'p\xfa\xa6\x0fM\x7f\xb4o\xae\xb1\x1dv\x82\xacky\xd6\xe4\x93\x0b\x00\x86\xc6&' SQLALCHEMY_DATABASE_URI = os.environ.get('FLASK_DATABASE_URL') diff --git a/customers/models.py b/customers/models.py index bc3b714..ff8a482 100644 --- a/customers/models.py +++ b/customers/models.py @@ -11,9 +11,9 @@ class Customer(db.Model): email = db.Column(db.String(150), unique=False) address = db.Column(db.String(80)) mobile_phone = db.Column(db.String(80)) - is_dormant = db.Column(db.Boolean) + loans = db.relationship('Loan', backref='customer', lazy='dynamic') - def __init__(self, first_name=None, last_name=None, number_shares=0, email=None, address=None, mobile_phone=None, is_dormant=0): + def __init__(self, first_name=None, last_name=None, number_shares=0, email=None, address=None, mobile_phone=None): self.first_name = first_name self.last_name = last_name self.name = first_name + ' ' + last_name @@ -21,5 +21,7 @@ def __init__(self, first_name=None, last_name=None, number_shares=0, email=None, self.email = email self.address = address self.mobile_phone = mobile_phone - self.is_dormant = is_dormant + + def __repr__(self): + return self.name diff --git a/customers/templates/customers.html b/customers/templates/customers.html index 31ed23a..d93a330 100644 --- a/customers/templates/customers.html +++ b/customers/templates/customers.html @@ -39,18 +39,18 @@ {% if current_user.can_update or current_user.can_delete: %} {% if current_user.can_update: %} - + {% endif %} {% if current_user.can_delete : %} - + {% endif %} {% endif %} - {{ customer.first_name }} {{ customer.last_name }} + {{ customer }} {{ customer.number_shares }} {{ customer.email }} {{ customer.mobile_phone }} diff --git a/customers/views.py b/customers/views.py index eb2821a..047632f 100644 --- a/customers/views.py +++ b/customers/views.py @@ -12,7 +12,7 @@ def customers(): from models import Customer try: - query_customers = Customer.query.filter(Customer.is_dormant == 0).order_by(Customer.first_name) + query_customers = Customer.query.order_by(Customer.name.asc()) return render_template('customers.html', query_customers=query_customers) except TemplateNotFound: abort(404) @@ -29,7 +29,7 @@ def newcustomer(): if request.method == 'GET': form.number_shares.data = 0 if form.validate_on_submit(): - customer = Customer.query.filter(Customer.name==form.first_name.data.strip()+ ' ' + form.last_name.data.strip()).filter(Customer.is_dormant == 0).first() + customer = Customer.query.filter(Customer.name==form.first_name.data.strip()+ ' ' + form.last_name.data.strip()).first() if customer is None: customer = Customer( first_name=form.first_name.data.strip(), @@ -37,8 +37,7 @@ def newcustomer(): number_shares=form.number_shares.data, email=form.email.data.strip(), address=form.address.data.strip(), - mobile_phone=form.mobile_phone.data.strip(), - is_dormant=0 + mobile_phone=form.mobile_phone.data.strip() ) db.session.add(customer) db.session.commit() @@ -59,7 +58,7 @@ def editcustomer(id): if not current_user.can_update: return redirect(url_for('customers.customers')) form = EditCustomerForm(request.form) - customer = Customer.query.filter(Customer.id == id).filter(Customer.is_dormant == 0).first() + customer = Customer.query.filter_by(id=id).first() if customer is None: flash(u'Cannot find customer.', 'danger') return redirect(url_for('customers.customers')) @@ -69,7 +68,7 @@ def editcustomer(id): new_name = request.form['first_name'] + ' ' + request.form['last_name'] name_exist = None if current_name != new_name: - name_exist = Customer.query.filter(Customer.name==request.form['first_name'].strip() + ' ' + request.form['last_name'].strip()).filter(Customer.is_dormant == 0).first() + name_exist = Customer.query.filter(Customer.name==request.form['first_name'].strip() + ' ' + request.form['last_name'].strip()).first() if form.validate_on_submit() and name_exist is None: customer.first_name = request.form['first_name'] customer.last_name = request.form['last_name'] @@ -102,12 +101,12 @@ def deletecustomer(): if not current_user.can_delete: return redirect(url_for('customers.customers')) id = request.form['id'] - customer = Customer.query.filter(Customer.id == id).filter(Customer.is_dormant == 0).first() + customer = Customer.query.filter_by(id=id).first() if customer is None: flash(u'Cannot find customer.', 'danger') return redirect(url_for('customers.customers')) else: - customer.is_dormant = 1 + db.session.delete(customer) db.session.commit() flash(u'Record was successfully deleted.', 'success') return redirect(url_for('customers.customers')) diff --git a/db_create.py b/db_create.py index c687c66..27cafe1 100644 --- a/db_create.py +++ b/db_create.py @@ -15,16 +15,16 @@ # create the database and the db table db.create_all() #insert -user = User(1, 1, 1, "guest","marzim@gmail.com", "jasper", 0) +user = User(1, 1, 1, "guest","marzim@gmail.com", "jasper") db.session.add(user) first_names = [ 'test', 'test2', 'test3', 'test4', 'test5', 'test6', 'test7'] last_names = [ 'ting', 'ting2', 'ting3', 'ting4', 'ting5', 'ting6', 'ting7'] for i in range(len(first_names)): - customer = Customer(first_names[i], last_names[i], i + 1, first_names[i].lower() + "@gmail.com", - first_names[i].lower() + " address", "1234567", 0) - db.session.add(customer) - loan = Loan(i+1, 1000, 3, 100, 1030, 100, 930, date.today(), date.today(), date.today(), 0) + c = Customer(first_names[i], last_names[i], i + 1, first_names[i].lower() + "@gmail.com", + first_names[i].lower() + " address", "1234567") + db.session.add(c) + loan = Loan(customer=c, amount=1000, interest=3, payment=100, total_payable=1030, total_payment=100, outstanding_balance=930, fully_paid_on=date.today(), date_release=date.today(), date_due=date.today()) db.session.add(loan) diff --git a/home/templates/modalform.html b/home/templates/modalform.html index e4d26b6..a5b16d2 100644 --- a/home/templates/modalform.html +++ b/home/templates/modalform.html @@ -31,11 +31,12 @@

Dele
diff --git a/loans/forms.py b/loans/forms.py index 87359a7..ba4648d 100644 --- a/loans/forms.py +++ b/loans/forms.py @@ -19,24 +19,17 @@ class AddForm(Form): outstanding_balance = FloatField('outstanding_balance') class EditForm(Form): - first_name = StringField( - 'first_name', - validators=[DataRequired(), Length(min=3, max=25)] - ) - last_name = StringField( - 'last_name', - validators=[DataRequired(), Length(min=3, max=25)] - ) - number_shares = IntegerField('number_shares') - email = StringField( - 'email', - validators=[DataRequired(), Email(message=None), Length(min=6, max=40)] - ) - address = StringField( - 'address', - validators=[DataRequired(), Length(min=3, max=25)] - ) - mobile_phone = StringField( - 'mobile_phone', - validators=[DataRequired(), Length(min=3, max=25)] - ) \ No newline at end of file + customer_name = SelectField(u'Customers', coerce=int) + + date_release = StringField( + 'date_release') + date_due = StringField( + 'date_release') + fully_paid_on = StringField( + 'fully_paid_on') + amount = FloatField('amount') + interest = SelectField(u'Interest', coerce=int) + total_payable = FloatField('total_payable') + payment = FloatField('payment') + total_payment = FloatField('total_payment') + outstanding_balance = FloatField('outstanding_balance') \ No newline at end of file diff --git a/loans/models.py b/loans/models.py index 62c4af5..e765499 100644 --- a/loans/models.py +++ b/loans/models.py @@ -4,7 +4,6 @@ class Loan(db.Model): __tablename__ = "loans" id = db.Column(db.Integer, primary_key=True) - customer_id = db.Column(db.Integer, db.ForeignKey("customers.id")) amount = db.Column(db.Float, unique=False) interest = db.Column(db.Float, unique=False) payment = db.Column(db.Float, unique=False) @@ -14,21 +13,19 @@ class Loan(db.Model): fully_paid_on = db.Column(db.String(80)) date_release = db.Column(db.String(80)) date_due = db.Column(db.String(80)) - is_dormant = db.Column(db.Boolean) - customer = db.relationship('Customer', backref='customers') + customer_id = db.Column(db.Integer, db.ForeignKey("customers.id")) - def __init__(self, customer_id=0, amount=0, interest=0, payment=0, total_payable=0, total_payment=0, outstanding_balance=0, fully_paid_on=None, date_release=None, date_due=None, is_dormant=0): - self.customer_id = customer_id - self.amount = amount - self.interest = interest - self.payment = payment - self.total_payable = total_payable - self.total_payment = total_payment - self.outstanding_balance = outstanding_balance - self.fully_paid_on = fully_paid_on - self.date_release = date_release - self.date_due = date_due - self.is_dormant = is_dormant + # def __init__(self, customer_id=0, amount=0, interest=0, payment=0, total_payable=0, total_payment=0, outstanding_balance=0, fully_paid_on=None, date_release=None, date_due=None): + # self.customer_id = customer_id + # self.amount = amount + # self.interest = interest + # self.payment = payment + # self.total_payable = total_payable + # self.total_payment = total_payment + # self.outstanding_balance = outstanding_balance + # self.fully_paid_on = fully_paid_on + # self.date_release = date_release + # self.date_due = date_due class Interest(db.Model): __tablename__ = "interest" diff --git a/loans/templates/addloan.html b/loans/templates/addloan.html index 24644e1..eed6635 100644 --- a/loans/templates/addloan.html +++ b/loans/templates/addloan.html @@ -28,7 +28,7 @@

- {{ form.customer_name(type="text", autofocus="True", class="form-control") }} + {{ render_field(form.customer_name, type="text", autofocus="True", class="form-control") }}

@@ -58,7 +58,7 @@

- {{ form.interest(type="text", class="form-control", style="width:75%;") }} + {{ render_field(form.interest, type="text", class="form-control", style="width:75%;") }}

diff --git a/loans/templates/editloan.html b/loans/templates/editloan.html index 025e99c..b8d97e2 100644 --- a/loans/templates/editloan.html +++ b/loans/templates/editloan.html @@ -14,11 +14,11 @@
- + {{ form.csrf_token }} -

- {{ form.name(type="text", autofocus="True", class="form-control") }} -

+
+
+ +

+ {{ render_field(form.customer_name, type="text", autofocus="True", class="form-control") }} +

+
+
+ +
+ + +
+
+
+
+
+ +

+ {{ render_field(form.amount, type="text", class="form-control") }} +

+
+
+ +
+ + +
+
+
+
+
+ +

+ {{ render_field(form.interest, type="text", class="form-control", style="width:75%;") }} +

+
+
+ + {{ render_field(form.total_payable, type="text", class="form-control", style="width:75%;") }} +
+
+
+
+ +

+ {{ form.payment(type="text", class="form-control", style="width:75%;") }} +

+
+
+ + {{ render_field(form.total_payment, type="text", class="form-control", style="width:75%;") }} - +
+
+
+
+ +
+ + +
+
+
+ + {{ render_field(form.outstanding_balance, type="text", class="form-control", style="width:75%;") }} +
+
+
+
+
+ +
+
{% endblock %}
diff --git a/loans/templates/loans.html b/loans/templates/loans.html index da68d64..8982166 100644 --- a/loans/templates/loans.html +++ b/loans/templates/loans.html @@ -13,7 +13,7 @@ {% block membercontent %}