Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mobashshir005 committed Nov 19, 2020
1 parent 90f07f5 commit 37c4208
Show file tree
Hide file tree
Showing 25 changed files with 679 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/IMS.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file added Screenshots/Report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/add_location.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/add_product.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/location.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/movements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/product.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/update_location.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/update_movements.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Screenshots/update_product.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
176 changes: 176 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
from flask import Flask, render_template, request, redirect, flash
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime

app = Flask(__name__)
app.secret_key = 'my_secret_key'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = "mysql://root:@localhost/ims"
db = SQLAlchemy(app)


class Product(db.Model):
product_id = db.Column(db.Integer, primary_key=True)
product_name = db.Column(db.String(12), nullable=False)


class Location(db.Model):
location_id = db.Column(db.Integer, primary_key=True)
location_name = db.Column(db.String(12), nullable=False)


class Movements(db.Model):
movement_id = db.Column(db.Integer, primary_key=True)
from_location = db.Column(db.String(12), nullable=True)
to_location = db.Column(db.String(12), nullable=True)
product = db.Column(db.String(12), nullable=False)
qty = db.Column(db.Integer, nullable=False)
timestamp = db.Column(db.String(20), nullable=False, default=datetime.now())


@app.route('/product', methods=['GET', 'POST'])
def product():
if request.method == 'POST':
product_name = request.form.get('pname')
entry = Product(product_name=product_name)
try:
db.session.add(entry)
db.session.commit()
return redirect('/product')
except:
return "Database error"
products = Product.query.all()

return render_template('product.html', p=True, products=products)


@app.route('/p_update/<string:id>', methods=['GET', 'POST'])
def p_update(id):
if request.method == 'POST':
product_name = request.form.get('pname')
products = Product.query.filter_by(product_id=id).first()
products.product_name = product_name
try:
db.session.commit()
return redirect('/p_update/' + id)
except:
return "Database error"
product = Product.query.filter_by(product_id=id).first()
return render_template('p_update.html', p=True, product=product, id=id)


@app.route('/location', methods=['GET', 'POST'])
def location():
if request.method == 'POST':
location_name = request.form.get('lname')
entry = Location(location_name=location_name)
try:
db.session.add(entry)
db.session.commit()
return redirect('/location')
except:
return "Database error"
locations = Location.query.all()

return render_template('location.html', l=True, locations=locations)


@app.route('/l_update/<string:id>', methods=['GET', 'POST'])
def l_update(id):
if request.method == 'POST':
location_name = request.form.get('lname')
locations = Location.query.filter_by(location_id=id).first()
locations.location_name = location_name
try:
db.session.commit()
return redirect('/l_update/' + id)
except:
return "Database error"
location = Location.query.filter_by(location_id=id).first()
return render_template('l_update.html', l=True, location=location, id=id)


@app.route('/movement', methods=['GET', 'POST'])
def movement():
if request.method == 'POST':
# date = datetime.now()
from_location = request.form.get('f_location')
to_location = request.form.get('t_location')
product = request.form.get('product')
qty = request.form.get('qty')
if from_location == "" or int(qty) < get_quantity(from_location, product):
entry = Movements(from_location=from_location, to_location=to_location, product=product,
qty=qty)
else:
flash('Not enough quantity is available')
return redirect('/movement')
try:
db.session.add(entry)
db.session.commit()
except:
return "Database error"

return redirect('/movement')

movements = Movements.query.all()
products = Product.query.all()
locations = Location.query.all()
return render_template('movement.html', m=True, products=products, locations=locations, movements=movements)


@app.route('/update_movement/<string:id>', methods=['GET', 'POST'])
def update_movement(id):
if request.method == 'POST':
date = datetime.now()
from_location = request.form.get('f_location')
to_location = request.form.get('t_location')
product = request.form.get('product')
qty = request.form.get('qty')
movements = Movements.query.filter_by(movement_id=id).first()
movements.date = date
movements.from_location = from_location
movements.to_location = to_location
movements.product = product
movements.qty = qty
try:
db.session.commit()
flash('Movement Updated Successfully!')
return redirect('/update_movement/' + id)
except:
return "Database error"
movements = Movements.query.filter_by(movement_id=id).first()
locations = Location.query.all()
products = Product.query.all()
return render_template('update_movement.html', m=True, movements=movements, id=id, locations=locations,
products=products)


@app.route('/')
def report():
locations = Location.query.all()
products = Product.query.all()
report = []
for location in locations:
for product in products:
row = {}
row["location"] = location.location_name
row["product"] = product.product_name
row["quantity"] = get_quantity(location.location_name, product.product_name)
report.append(row)

return render_template('report.html', r=True, report=report)


def get_quantity(location, product):
qty = 0
add_entries = Movements.query.filter_by(to_location=location, product=product).all()
sub_entries = Movements.query.filter_by(from_location=location, product=product).all()
for entry in add_entries:
qty += entry.qty
for entry in sub_entries:
qty -= entry.qty

return qty


app.run(debug=True)
Binary file added static/img/home-bg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/img/in.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions templates/l_update.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{% extends "template.html" %}
{% block body %}
<div class="container" style="text-align: center; margin-top: 20px;">
<form action="/l_update/{{id}}" method="POST">
<div class="form-group">
<label for="text"><h1> Update Location</h1></label>
<input type="text" class="form-control" name="lname" id="exampleInputEmail1" aria-describedby="text" value="{{location.location_name}}">
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>
{% endblock %}

76 changes: 76 additions & 0 deletions templates/location.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{% extends "template.html" %}
{% block body %}
<br>
<div class="container">
<button type="button" class="btn btn-primary float-left" data-toggle="modal" data-target="#myModal">Add
Location</button>
<div class="table-responsive">
<br>
<!-- Trigger the modal with a button -->
<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog" style="margin-top: 100px;">

<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button>
</div>
<div class="modal-body">
<form action="/location" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Location</label>
<input type="text" class="form-control" id="lname" name="lname" placeholder="Enter Location">
</div>
<button type="submit" class="btn btn-primary">Add</button>
</form>
</div>
</div>
</div>
</div>
</div>

<table class="table table-borderless" id="myTable">
<thead class="thead-light">
<tr>
<th>Location_ID</th>
<th>Location_Name</th>
<th>Update_Location</th>

</tr>
</thead>
<tbody>
{% for loc in locations %}
<tr>
<td>{{loc.location_id}}</td>
<td>{{loc.location_name}}</td>
<td><a href="/l_update/{{loc.location_id}}"><button class="btn btn-outline-dark btn-sm">Edit</button></a></td>
</tr>
{% endfor %}
</tbody>
</table>
<hr>
</div>

<!-- <script>
function myFunction() {
var input, filter, table, tr, td, i, txtValue;
input = document.getElementById("myInput");
filter = input.value.toUpperCase();
table = document.getElementById("lTable");
tr = table.getElementsByTagName("tr");
for (i = 0; i < tr.length; i++) {
td = tr[i].getElementsByTagName("td")[1];
if (td) {
txtValue = td.textContent || td.innerText;
if (txtValue.toUpperCase().indexOf(filter) > -1) {
tr[i].style.display = "";
} else {
tr[i].style.display = "none";
}
}
}
}
</script> -->

{% endblock %}
Loading

0 comments on commit 37c4208

Please sign in to comment.