def inventories(): inventories = Inventories.fetch_records() # print(inventories) cursor.execute("""SELECT inv_id, sum(stock) as "stock" FROM ((SELECT st.inv_id, sum(stock) as "stock" FROM public.stocks as st GROUP BY inv_id) union all (SELECT sa.inv_id, - sum(quantity) as "quantity" FROM public.sales as sa GROUP BY inv_id) ) stsa GROUP BY inv_id ORDER BY inv_id;""") available_stock = cursor.fetchall() if request.method == 'POST': name = request.form['name'] mytype = request.form['mytype'] buying_price = request.form['buying_price'] selling_price = request.form['selling_price'] inventory = Inventories(name=name, mytype=mytype, buying_price=buying_price, selling_price=selling_price) inventory.create_record() return redirect(url_for('inventories')) return render_template('inventories.html', inventories=inventories, available_stock=available_stock)
def add_inventories(): if request.method == 'POST': name = request.form['name'] type = request.form['type'] buying_price = request.form['buying_price'] selling_price = request.form['selling_price'] stock = request.form['stock'] record = Inventories(name=name, buying_price=buying_price, selling_price=selling_price, type=type, stock=stock) record.add_records() return redirect(url_for('index'))
def delete_item(id): record = Inventories.fetch_a_record(id) try: record.delete_record() except: return 'Could not delete item, confirm there are no sales' return redirect(url_for('add_inventories'))
def hello_world(): records = Inventories.fetch_all_records() print(type(records)) return render_template('index.html', records=records)
def salez(id): record = Inventories.fetch_one_record(id) # print(id) # return 'T' if record: if request.method == 'POST': quantity = request.form['Quantity'] newStock = record.stock - int(quantity) print(quantity) # print(newStock) record.stock = newStock db.session.commit() #Updating to the sales table sales = Sales(inv_id=id, quantity=quantity) sales.add_records() #mideule to notify sale of an item flash('You Successfuly made a Sale', 'success') return redirect(url_for('hello_world'))
def delete(id): record = Inventories.fetch_one_record(id) # print(record.id) # print(record.name) db.session.delete(record) db.session.commit() # flash('Item successfully deleted from inventory','danger') return redirect(url_for('hello_world'))
def add_inventory(): if request.method == 'POST': name = request.form['name'] type = request.form['type'] buying_price = request.form['bp'] selling_price = request.form['sp'] stock = request.form['Stock'] # print(name) # print(type) # print(buying_price) # print(selling_price) record = Inventories(name=name, type=type , buying_price=buying_price, selling_price=selling_price, stock=stock) record.add_records() # return 'Naibei' return redirect(url_for('hello_world'))
def delete(id): # print(id) record = Inventories.fetch_one_record(id) # print(record.name) db.session.delete(record) db.session.commit() flash('You have succesfully deleted the inventory', 'danger') return redirect(url_for('hello_world'))
def deleteInventory(id): delete_inventory = Inventories.fetch_by_id(id) if delete_inventory: print('Record deleted successfully') return redirect(url_for('inventories')) else: print('record not found') return redirect(url_for('inventories'))
def makeSales(id): record = Inventories.fetch_one_record(id) if record: if request.method == 'POST': quantity = request.form['quantity'] newStock = record.stock - int(quantity) record.stock = newStock db.session.commit() flash('You successfully made a sale', 'success') return redirect(url_for('add_inventories'))
def update_sale(id): record = Inventories.fetch_a_record(id) if request.method == 'POST': record.name = request.form['name'] record.type = request.form['type'] record.buying_price = request.form['buying_price'] record.selling_price = request.form['selling_price'] record.stock = request.form['stock'] db.session.commit() return redirect(url_for('index')) return render_template('update_sale.html', record=record)
def edit(id): record = Inventories.fetch_one_record(id) if request.method == 'POST': record.name = request.form['name'] record.type = request.form['type'] record.buying_price = request.form['buying_price'] record.selling_price = request.form['selling_price'] record.stock = request.form['stock'] db.session.commit() # return redirect(url_for('hello_world')) return render_template('edit.html',record=record)
def makeSale(id): rec = Inventories.fetch_one_record(id) if request.method == 'POST': try: newStock = rec.stock - int(request.form['quantity']) rec.stock = newStock db.session.commit() # saleRecord = Sales(inv_id=id, quantity=) except: return 'issue in posting' else: pass return redirect(url_for('hello_world'))
def make_sales(id): record = Inventories.fetch_one_record(id) if record: print(id) if request.method =='POST' : quantity = request.form['quantity'] new_stock= record.stock - int(quantity) record.stock = new_stock db.session.commit() # sales = Sales(inv_id=id) flash ('Sale made successfully','success') print(quantity) return redirect(url_for('hello_world',record=record))
def make_sale(id1): print(id1) record = Inventories.fetch_a_record(id1) if record: if request.method == 'POST': quantity = request.form['quantity'] inv_id = request.form['inv_id'] if int(quantity) < record.stock: new_stock = record.stock - int(quantity) record.stock = new_stock sale = Sales(inv_id=inv_id, quantity=quantity, created_at=datetime.now()) sale.sell() db.session.commit() flash('Successful Sale') else: flash('stock not available') return redirect(url_for('add_inventories'))
def add_inventory(): if request.method == 'POST': name = request.form['name'] type = request.form['type'] buying_price = request.form['buying_price'] selling_price = request.form['selling_price'] stock = request.form['stock'] # print(Name) # print(Type) # print(buying_price) # print(selling_price) # print(Stock) record = Inventories(name=name,type=type,buying_price=buying_price,selling_price=selling_price, stock=stock) # record.add_records(record) db.session.add(record) db.session.commit() return redirect(url_for('hello_world'))
def inventories(): r = Inventories.query.all() cur.execute("""SELECT inv_id, sum(quantity) as "stock" FROM ((SELECT st.inv_id, sum(stock) as "quantity" FROM public.new_stock as st GROUP BY inv_id) union all (SELECT sa.inv_id, - sum(quantity) as "quantity" FROM public.new_sales as sa GROUP BY inv_id) ) stsa GROUP BY inv_id ORDER BY inv_id;""") remstock = cur.fetchall() for each in remstock: print(each[1]) if request.method == 'POST': name = request.form['name'] type = request.form['type'] buying_price = request.form['buying_price'] selling_price = request.form['selling_price'] records = Inventories(name=name, type=type, buying_price=buying_price, selling_price=selling_price) db.session.add(records) db.session.commit() return redirect(url_for('inventories')) # print(name) # print(type) # print(buying_price) # print(selling_price) return render_template('inventories.html', record=r, remstock=remstock)
def hello_world(): x = 'stan' records = Inventories.fetch_all_records() return render_template('index.html', records=records, x=x)
def hello_world(): x = 'Leon' records = Inventories.fetch_all_records()#.order_by(id).asc # tasks = Inventories.query.order_by(id).asc.all() # return render_template('index.html', tasks=tasks) return render_template('index.html', records=records, x=x)
def viewSales(id): record = Inventories.fetch_one_record(id) return render_template('viewsales.html', record=record)
def viewsales(id): record = Inventories.fetch_one_record(id) db.session.commit() return render_template('sales.html', record=record)