Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[refactor]updated invoice to be automatic #76

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions App/controllers/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,12 +195,15 @@ def import_transactionLog(uploaded_file):
except:
print('Invalid date conversation')
restore_transaction(tL['id'],tL['rent_id'], tL['currency'],tL['transaction_date'], tL['amount'], tL['description'], tL['type'], tL['receipt_number'])
seq = Sequence(name='transaction_log_id_seq')
seq = Sequence(name='transaction_log_id_seq')
seq2 = Sequence(name='transaction_log_receipt_number_seq')
key = db.session.execute(seq)
key2 = db.session.execute(seq2)

while (key < tLog_json[len(tLog_json)-1]['id']):
key = db.session.execute(seq)

db.session.execute(seq2)

return True


Expand Down
13 changes: 7 additions & 6 deletions App/controllers/transactionLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@
from sqlalchemy import or_,Sequence
from sqlalchemy.exc import SQLAlchemyError

def add_new_transaction(rent_id, currency, transaction_date, amount, description, t_type,receipt_number):
seq = Sequence(name='transaction_log_id_seq')
def add_new_transaction(rent_id, currency, transaction_date, amount, description, t_type):
try:
new_transaction = TransactionLog(rent_id, currency,transaction_date, amount, description, t_type,receipt_number)
new_transaction = TransactionLog(rent_id, currency,transaction_date, amount, description, t_type)
rent = Rent.query.filter_by(id=rent_id).first()
rent.update_payments(amount)
db.session.add(new_transaction)
db.session.add(rent)
db.session.execute(seq)
db.session.commit()
return new_transaction
except SQLAlchemyError as e:
Expand All @@ -21,14 +19,17 @@ def add_new_transaction(rent_id, currency, transaction_date, amount, description

def restore_transaction(id,rent_id, currency, transaction_date, amount, description, t_type,receipt_number):
try:
new_transaction = TransactionLog(rent_id, currency,transaction_date, amount, description, t_type,receipt_number)
new_transaction = TransactionLog(rent_id, currency,transaction_date, amount, description, t_type)
new_transaction.id = id
new_transaction.receipt_number = id
rent = Rent.query.filter_by(id=rent_id).first()
rent.update_payments(amount)
db.session.add(new_transaction)
db.session.add(rent)
seq = Sequence(name='transaction_log_id_seq')
key = db.session.execute(seq)
seq2 = Sequence(name='transaction_log_receipt_number_seq')
db.session.execute(seq)
db.session.execute(seq2)
db.session.commit()
return new_transaction
except SQLAlchemyError as e:
Expand Down
9 changes: 6 additions & 3 deletions App/models/transactionLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
from App.database import db
from enum import Enum

from sqlalchemy import Sequence

seq = Sequence('transaction_log_receipt_number_seq')

class TransactionType(Enum):
CREDIT = "credit"
DEBIT = "debit"
Expand All @@ -13,18 +17,17 @@ class TransactionLog(db.Model):
transaction_date = db.Column(db.Date,nullable = False)
amount = db.Column(db.Float , nullable = False)
description = db.Column(db.String, nullable = False)
receipt_number = db.Column(db.Integer,nullable=False,unique=True)
receipt_number = db.Column(db.Integer,seq,nullable=False,unique=True)
type = db.Column(db.Enum(TransactionType), nullable = False)

def __init__(self, rent_id, currency, transaction_date, amount, description, type,receipt_number):
def __init__(self, rent_id, currency, transaction_date, amount, description, type):
self.rent_id = rent_id
self.currency = currency
self.transaction_date = transaction_date
self.amount = amount
self.description = description
if type.upper() in TransactionType.__members__:
self.type = TransactionType[type.upper()]
self.receipt_number = receipt_number

def toJSON(self):
return {
Expand Down
1 change: 0 additions & 1 deletion App/static/lockers.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,6 @@ function createRent(studentID,locker_code){
date_returned: fields['date_returned'].value,
currency:fields2['currency'].value,
amount:fields2['t_amount'].value,
r_number:fields2['receipt_number'].value,
t_date:fields2['transaction_date'].value,
t_type:fields2['t_type'].value
}
Expand Down
5 changes: 0 additions & 5 deletions App/static/manage_locker_offline.html
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,6 @@ <h6 style="font-weight: bold;">New Transaction </h6>
<option value="credit">credit</option>
</select>
</div>
<div class="col s6">
<p> Receipt Number </p>
<input type="number" class="validate white-text" id="t_receipt" name="receipt_number">
</div>
<div class="input-field col s8 m8 offset-m4" style="display:inline;">
<input type="submit" class="right purple darken-4 waves-light btn">
<a class="red darken-4 white-text right modal-close waves-light btn">Cancel</a>
Expand Down Expand Up @@ -761,7 +757,6 @@ <h6 style="font-weight: bold;">Swap Rent</h6>
amount: fields['amount'].value,
description:fields['description'].value,
t_type:fields['t_type'].value,
receipt_number:fields['receipt_number'].value,
}
elem = document.getElementById('new_transaction');
instance = M.Modal.getInstance(elem)
Expand Down
2 changes: 1 addition & 1 deletion App/static/sw.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const {precacheAndRoute,cleanupOutdatedCaches,addRoute} = workbox.precaching;
const {CacheableResponse, CacheableResponsePlugin} = workbox.cacheableResponse;

cleanupOutdatedCaches()
precacheAndRoute([{"revision":"bc56a6869ac03cd8815461a8a58ca256","url":"autocomplete.js"},{"revision":"9d295ec8b213fdfaac1595e739a950ef","url":"keep_alive.js"},{"revision":"1dae51f3d83761609553b73750834ac4","url":"lockers.js"},{"revision":"870b5ea4295065881458d40c6df53a78","url":"main.js"},{"revision":"fb0a89c8298881c0a8ddd6f05866a486","url":"manage_locker_offline.html"},{"revision":"5c939ef677a57602e5e12eaa34058ead","url":"map_init.js"},{"revision":"b0663391a6dd5efed956259f29fa18dd","url":"materialize.css"},{"revision":"74ac8fd1cd0b94f532c54d4c707a86ae","url":"materialize.js"},{"revision":"ec1df3ba49973dcb9ff212f052d39483","url":"materialize.min.css"},{"revision":"5dcfc8944ed380b2215dc28b3f13835f","url":"materialize.min.js"},{"revision":"b7a97dc36dffb61a3b3e165b9dbe20d2","url":"offline.html"},{"revision":"7a2b4050bd5b0159ba5101b00d60b40f","url":"static-user.html"},{"revision":"ceac046cad1656146e8d521968b87cda","url":"style.css"},{"revision":"1d8179f18fcc6c658c386f9f30ef126b","url":"util.js"},{"revision":"2cd1cbbe5f9d94f135c89263d2eb4d2b","url":"workbox-a482575e.js"}]);
precacheAndRoute([{"revision":"bc56a6869ac03cd8815461a8a58ca256","url":"autocomplete.js"},{"revision":"9d295ec8b213fdfaac1595e739a950ef","url":"keep_alive.js"},{"revision":"fd841d32365795926b84a5e556672d9f","url":"lockers.js"},{"revision":"870b5ea4295065881458d40c6df53a78","url":"main.js"},{"revision":"c01b9890e3758f1d282b70956b1ee70f","url":"manage_locker_offline.html"},{"revision":"5c939ef677a57602e5e12eaa34058ead","url":"map_init.js"},{"revision":"b0663391a6dd5efed956259f29fa18dd","url":"materialize.css"},{"revision":"74ac8fd1cd0b94f532c54d4c707a86ae","url":"materialize.js"},{"revision":"ec1df3ba49973dcb9ff212f052d39483","url":"materialize.min.css"},{"revision":"5dcfc8944ed380b2215dc28b3f13835f","url":"materialize.min.js"},{"revision":"b7a97dc36dffb61a3b3e165b9dbe20d2","url":"offline.html"},{"revision":"7a2b4050bd5b0159ba5101b00d60b40f","url":"static-user.html"},{"revision":"ceac046cad1656146e8d521968b87cda","url":"style.css"},{"revision":"1d8179f18fcc6c658c386f9f30ef126b","url":"util.js"},{"revision":"2cd1cbbe5f9d94f135c89263d2eb4d2b","url":"workbox-a482575e.js"}]);

setDefaultHandler(new NetworkFirst());

Expand Down
5 changes: 0 additions & 5 deletions App/templates/addrent.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,11 +160,6 @@ <h6 style="font-weight: bold;">New Transaction </h6>
</select>
</div>

<div class="input-field col s12 m4">
<p> Receipt Number </p>
{{trans.receipt_number(size=18, class="validate")}}
</div>

<div class="input-field col s8 m8 offset-m4" style="display:inline;">
{{trans.submit(id="t_submit",class="purple darken-4 waves-light btn")}}
<a class="red darken-4 white-text right modal-close waves-light btn">Cancel</a>
Expand Down
4 changes: 0 additions & 4 deletions App/templates/manage_locker.html
Original file line number Diff line number Diff line change
Expand Up @@ -341,10 +341,6 @@ <h6 style="font-weight: bold;">New Transaction </h6>
{% endfor %}
</select>
</div>
<div class="col s6">
<p> Receipt Number </p>
{{trans.receipt_number(size=18, class="validate white-text")}}
</div>
</div>
</div>
<div class="modal-footer grey darken-3">
Expand Down
4 changes: 0 additions & 4 deletions App/templates/studentDetails.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,6 @@ <h6 style="font-weight: bold;">New Transaction </h6>
{% endfor %}
</select>
</div>
<div class="col s6">
<p> Receipt Number </p>
{{trans.receipt_number(size=18, class="validate white-text")}}
</div>
</div>
</div>
<div class="modal-footer grey darken-3">
Expand Down
5 changes: 0 additions & 5 deletions App/templates/transactionLog.html
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,6 @@ <h6 style="font-weight: bold;"> New Transaction </h6>
</select>
</div>

<div class="input-field col s12 m4">
<p> Receipt Number </p>
{{form.receipt_number(size=18, class="validate white-text")}}
</div>

<div class="input-field col s8 m8 offset-m4" style="display:inline;">
{{form.submit(class=" right purple darken-4 waves-light btn")}}
<a class="red darken-4 white-text right modal-close waves-light btn">Cancel</a>
Expand Down
10 changes: 5 additions & 5 deletions App/views/transactionLog.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def create_new_transaction():
amount = int(request.form.get('amount'))
description = request.form.get('description')
t_type =request.form.get('t_type')
receipt_number = request.form.get('receipt_number')
#receipt_number = request.form.get('receipt_number')

if t_type == "CREDIT":
if amount > 0:
Expand All @@ -56,7 +56,7 @@ def create_new_transaction():
if amount < 0:
amount = amount * -1

newTransaction = add_new_transaction (rent_id,currency,transaction_date,amount,description, t_type, receipt_number)
newTransaction = add_new_transaction (rent_id,currency,transaction_date,amount,description, t_type)

if not newTransaction:
flash('Error adding transaction')
Expand Down Expand Up @@ -103,7 +103,7 @@ def manage_transaction_pages_multi(offset):
next = num_pages
else:
next = offset + 1
return render_template('transactionLog.html', transaction_data = transaction_data, form = TransactionAdd(), search=SearchForm(),searchMode=False, num_pages= num_pages,current_page=1, next=next, previous= previous)
return render_template('transactionLog.html', transaction_data = transaction_data, form = TransactionAdd(), search=SearchForm(),searchMode=False, num_pages= num_pages,current_page=offset, next=next, previous= previous)

@transactionLog_views.route('/transactionLog/search/', methods=['GET'])
@login_required
Expand Down Expand Up @@ -151,9 +151,9 @@ def create_new_transaction_api():
amount = request.json.get('amount')
description = request.json.get('description')
t_type =request.json.get('t_type')
receipt_number = request.json.get('receipt_number')
#receipt_number = request.json.get('receipt_number')

newTransaction = add_new_transaction (rent_id,currency,transaction_date,amount,description, t_type, receipt_number)
newTransaction = add_new_transaction (rent_id,currency,transaction_date,amount,description, t_type)

if not newTransaction:
return jsonify({"error": "Rental not created"}),400
Expand Down
Loading