def home(): try: pie_chart = pygal.Pie() pie_chart.title = 'Inventory Type' pie_chart.add('Products', InventoryModel.getTypeCount('Product')) pie_chart.add('Services', InventoryModel.getTypeCount('Service')) pie_data = pie_chart.render_data_uri() return render_template("index.html", pietype=pie_data) except: return render_template('index.html')
def inventory(): x = InventoryModel.query.all() # for i in x: # print(i.Inv_name) if request.method == 'POST': Inv_name = request.form['inventory'] Inv_type = request.form['type'] BP = request.form['bp'] SP = request.form['sp'] Stock = request.form['stock'] RP = request.form['rp'] obj = InventoryModel(inv_name=Inv_name, inv_type=Inv_type, bp=BP, sp=SP, stock=Stock, rp=RP) db.session.add(obj) db.session.commit() print("submitted") return redirect(url_for("inventory")) # print(Inv_type) # print(BP) # print(SP) # print(Stock) # print(RP) # we a passing a variable to display the end product on you webpage. return render_template('inventory.html', inventories=x)
def hello_world(): pie_chart = pygal.Pie() pie_chart.title = 'services vs products in percentage' pie_chart.add('products', InventoryModel.getCountType("Product")) pie_chart.add('sales', InventoryModel.getCountType("Service")) graph_data = pie_chart.render_data_uri() conn = psycopg2.connect( "dbname='ims' user='******' host='localhost' password='******'") cur = conn.cursor() cur.execute( """SELECT (sum(i.bp * s.quantity)) as subtotal, EXTRACT(MONTH FROM s.created_date)as sales_month FROM sales as s join inventories as i on s.inv_id = i.id GROUP BY sales_month ORDER BY sales_month""") rows = cur.fetchall() # print(rows) x = [ "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" ] y = [] for r in rows: # x.append(r[1]) y.append(r[0]) line_chart = pygal.Line() line_chart.title = 'Subtotal of a period in %' line_chart.x_labels = map(str, x) line_chart.add('Subtotal', y) line_data = line_chart.render_data_uri() line_some = pygal.HorizontalStackedBar() line_some.title = 'Subtotal of a period in %' line_some.x_labels = map(str, x) line_some.add('Subtotal', y) line_some = line_some.render_data_uri() return render_template("index.html", graph_data=graph_data, line_data=line_data, line_some=line_some)
def delete(id): try: delete = InventoryModel.delete(id) if delete: print("record has been successfully deleted") return redirect(url_for('inventory')) except Exception: return redirect(url_for('inventory'))
def sales(): if request.method == 'POST': sales_qty = request.form['qty'] foreign_id = request.form['inventory_id'] if InventoryModel.update_stock(foreign_id, int(sales_qty)): print('stock update success') else: flash( 'Error, the quantity of sales entered is greater than stock available', 'danger') sales = SalesModel(inv_id=foreign_id, qty=sales_qty) db.session.add(sales) db.session.commit() print('sales saved') return redirect(url_for('inv'))
def sales(): if request.method == 'POST': quantity = request.form['quantity'] forkey = request.form['forkey'] if InventoryModel.update(id=forkey, qt=int(quantity)): print('success') sale = SalesModel(Inv_id=forkey, Quantity=quantity) db.session.add(sale) db.session.commit() else: print("You dont have enough stock") # print(quantity, forkey) # # print('success') # return redirect(url_for('inventory'))
def inv(): if request.method == 'POST': iname = request.form['name'] itype = request.form['type'] ibuying_price = request.form['bp'] iselling_price = request.form['sp'] istock = request.form['stock'] ireorder_point = request.form['rp'] entries = InventoryModel(invname=iname, invtype=itype, bp=ibuying_price, sp=iselling_price, stock=istock, rp=ireorder_point) db.session.add(entries) db.session.commit() print("Successfully added") all_entries = InventoryModel.query.all() return render_template('inv.html', invs=all_entries)
def edit_inv(): if request.method == 'POST': inv_id = request.form['inventory_id'] iname = request.form['name'] itype = request.form['type'] ibuying_price = request.form['bp'] iselling_price = request.form['sp'] istock = request.form['stock'] ireorder_point = request.form['rp'] if InventoryModel.update_inventory(id=int(inv_id), invname=iname, invtype=itype, bp=float(ibuying_price), sp=float(iselling_price), stock=int(istock), rp=int(ireorder_point)): print('stock update success') else: flash('Error, Fail', 'danger') print('error Fail') return redirect(url_for('inv'))